Hi All,
I have thousands of images each image has size (228*196), Each 7 images have same date. I need your help to create a code to do calculation which is (7th image - 2nd image)/(7th image + 2nd image).. I want to do that for each date.
Thank you
Reyadh

3 Kommentare

Walter Roberson
Walter Roberson am 6 Apr. 2017
How can you determine the date based on the file name? How can you determine which is the 2nd or 7th image based on the file name?
reyadh Albarakat
reyadh Albarakat am 7 Apr. 2017
Hi Walter Roberson,
yes there is a date and the band number here is the example:
((MOD09A1. A2000057.h21v05.006.2015136062042.hdf_sur_refl_ b01_clip.tif_mosaico_ream.tif)) ((MOD09A1. A2000057.h21v05.006.2015136062042.hdf_sur_refl_ b02_clip.tif_mosaico_ream.tif)) ((MOD09A1. A2000057.h21v05.006.2015136062042.hdf_sur_refl_ b03_clip.tif_mosaico_ream.tif)) ((MOD09A1. A2000057.h21v05.006.2015136062042.hdf_sur_refl_ b04_clip.tif_mosaico_ream.tif)) ((MOD09A1. A2000057.h21v05.006.2015136062042.hdf_sur_refl_ b05_clip.tif_mosaico_ream.tif)) ((MOD09A1. A2000057.h21v05.006.2015136062042.hdf_sur_refl_ b06_clip.tif_mosaico_ream.tif)) ((MOD09A1. A2000057.h21v05.006.2015136062042.hdf_sur_refl_ b07_clip.tif_mosaico_ream.tif))

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 7 Apr. 2017

2 Stimmen

dinfo = dir('*_b02_clip.tif_mosaico_ream.tif');
nfile = length(dinfo);
filenames = {dinfo.name};
for K = 1 : nfile
b2_file = filenames{K};
b7_file = b2_file; b7_file(end-27) = '7';
b2_data = double( imread(b2_file) );
b7_data = double( imread(b7_file) );
result = (b7_data - b2_data) ./ (b7_data + b2_data);
%now what?
end

6 Kommentare

reyadh Albarakat
reyadh Albarakat am 7 Apr. 2017
Bearbeitet: Walter Roberson am 7 Apr. 2017
Thank you Walter for reply
I got this error
((Error using imread))
is this loop for all date?. As I said each date has 7 bands, this date which A2000057 (year:2000 day:57) and next 8 days has new 7 bands like this
((MOD09A1. A2000065.h21v05.006.2015136062016.hdf_sur_refl_ b01_clip.tif_mosaico_ream.tif))
So this continue from 2000057 (year:2000 day:57) to A2016217 (year:2016 day:217).
Is it clear now?
Walter Roberson
Walter Roberson am 7 Apr. 2017
It looks like my (end-27) should be (end-26)
However, if the file name includes literal '(' or ')' or '*' characters then the count will need to be adjusted at the very least, and I am not certain imread() would be able to read files with those in the name. Possibly it could on OS-X or Linux.
reyadh Albarakat
reyadh Albarakat am 7 Apr. 2017
Hi Walter, By the way I got b2_data matrix (228*196) Why you used (end-27)? this numbers don't represent the date. the numbers that represents the data for images is A2000057 (year:2000 day:57) and A2000065 (year:2000 day:65) till A2016217 (year:2016 day:217)
I am not specifically advancing by date. You asked that the 7th image for each date be manipulated against the 2nd image for each date. I handle that by searching for all of the 2nd images (the b02 files), and for each one encountered, replace the 'b02' with 'b07'.
To generalize a little:
dinfo = dir('*_b02_clip.tif_mosaico_ream.tif');
nfile = length(dinfo);
filenames = {dinfo.name};
for K = 1 : nfile
b2_file = filenames{K};
band_pos = strfind(b2_file, '_b02');
b7_file = b2_file; b7_file(band_pos + 3) = '7';
b2_data = double( imread(b2_file) );
b7_data = double( imread(b7_file) );
result = (b7_data - b2_data) ./ (b7_data + b2_data);
%now what?
end
reyadh Albarakat
reyadh Albarakat am 7 Apr. 2017
Hi Walter,
Now it works BUT with only one data NOT for all dates.
Please Walter could you complete your help to make it a loop for all dates
I appreciate your efforts
Thank you
Reyadh
It already loops over all dates, provided that the band 2 files all end in b02_clip.tif_mosaico_ream.tif
If not then you could perhaps use
dinfo = dir('*_b02_*.tif');
If the b02 part is not consistent then you need to be clearer as to how you can recognize the band number.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Read, Write, and Modify Image finden Sie in Hilfe-Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by