I have numerous images from a directory that needs to be subtracted to another image and I don't know how to do it automatically in batch process.
Here's what I need to do:
- Create the output directory
- Check automatically if there are new files added in the input directory, if there are new files subtract immediately
- Subtract one image from the directory to another image from another directory
LEAP YEARS: REGULAR YEARS:
*2000, 2004, 2008, 2012, 2016, 2020...* *2001-2003, 2005-2007, 2009-2011, 2013-2015...*
January - 1-31 January - 1-31
February - 32-60 February - 32-59
March - 61-91 March - 60-90
April - 92-121 April - 91-120
May - 122-152 May - 121-151
June - 153-182 June - 152-181
July - 183-213 July - 182-212
August - 214-244 August - 213-243
September - 245-274 September - 244-273
October - 275-305 October - 274-304
November - 306-335 November - 305-334
December - 336-366 December - 335-365
Here are the sample file name for the images(these will be the minuend):
:there will only be 12 subtrahend(sample_file_jan.tif, sample_file_feb.tif, sample_file_march.tif . . .)
C2000060.A1_ABC.ABCD.tif - sample_file_feb.tif ------------------> the file was subtracted to feb because 060 is a day included in February (leap year)
C2002152.A1_ABC.ABCD.tif - sample_file_june.tif------------------> the file was subtracted to june because 152 is a day included in June (regular year)
C2000032.A1_ABC.ABCD.tif - sample_file_feb.tif------------------> the file was subtracted to feb because 032 is a day included in February (leap year)
C2001060.A1_ABC.ABCD.tif - sample_file_march.tif------------------> the file was subtracted to march because 060 is a day included in March (regular year)
where:
C = data name
2000 - year (leap year or regular year)
001 - julian date (leap year or regular year)
A1_ABC.ABCD.tif - extension name
If the year specified in the file name is 2000, 2004, 2008... then the date would be based on leap year. If the year specified in the file name is 2001-2003, 2005-2007, 2009-2011... then the date would be based on regular year.
If the date from the file name is based on the date from the leap years, then subtract the image to its corresponding subtrahend/month to where it should be subtracted. Repeat this step if the date are from the regular years.
Here is the script in subtracting images:
gdal_calculate --outfile=D:\path\to\file\difference.tif --calc="((image1-image2)/(image1
+image2))" --image2=D:\path\to\subtrahend\sample_file_feb.tif image1=D:\path\to\minuend\C2001060.A1_ABC.ABCD.tif --extent=INTERSECT