For loop for many images

조회 수: 1 (최근 30일)
reyadh Albarakat
reyadh Albarakat 2017년 4월 6일
댓글: Walter Roberson 2017년 4월 7일
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
reyadh Albarakat
reyadh Albarakat 2017년 4월 7일
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))

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2017년 4월 7일
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
reyadh Albarakat
reyadh Albarakat 2017년 4월 7일
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
Walter Roberson
Walter Roberson 2017년 4월 7일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Agriculture에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by