フィルターのクリア

How to do multiple saves during a loop?

2 ビュー (過去 30 日間)
Anson Hancock
Anson Hancock 2014 年 12 月 9 日
コメント済み: Anson Hancock 2014 年 12 月 9 日
I am trying to write a code into my script that will create an output .jpg for each of my .mat outputs. However it seems to only produce one .jpg because it overwrites each one. My code is listed below. Any help would be great.
Code:
%%Apply angle correction to rectified tranmittance corrected thermal images
% Calculate orientation angle for cells in dem
cd('C:\Users\anson_000\Documents\MATLAB\EMCT_Aug12\Rectified_thermal_im')
list=dir('*.mat');
% Calculate viewing distance components and angle vectdist_x = x0-Xdem; vectdist_y = y0-Ydem; vectdist_z = z0-Zdem; cosang = -(vectdist_x.*theta + vectdist_y.*phi + vectdist_z ) ./ ... ( sqrt( theta.^2+phi.^2+1 ) .* sqrt(vectdist_x.^2+vectdist_y.^2+vectdist_z.^2) );
cosang( cosang<0 ) = NaN;
for zz=1:length(list)
filename=list(zz).name;
output_name=['Temp_fullcorr_' filename(12:24)];
load(list(zz).name);
rect_rad_image = Rect_Planck_radconvers(10.25e-6,tempK_rect);
rad_rect_corrected = NaN*rect_rad_image;
temp_rect_corrected = NaN*tempK_rect;
hot_px = tempK_rect > 312; %Value in K?
rad_rect_corrected(hot_px)=rect_rad_image(hot_px)./cosang(hot_px);
temp_rect_corrected(hot_px)=tempK_rect(hot_px)./(cosang(hot_px).^(1/4));
save(output_name, 'temp_rect_corrected');
% Write an image to show the area identified as hot (white)
imwrite( uint8( cat(3, hot_px, hot_px, hot_px)*255 ), 'image_name.jpg', 'Quality', 100)
end

採用された回答

Orion
Orion 2014 年 12 月 9 日
I guess all your .jpg are named image_name.jpg ?
Inside the loop, you coded :
imwrite( uint8( cat(3, hot_px, hot_px, hot_px)*255 ), 'image_name.jpg', 'Quality', 100)
so the name is unchanged during the loop.
make something like :
MyImageName = sprintf('image_name%d.jpg',zz);
imwrite( uint8( cat(3, hot_px, hot_px, hot_px)*255 ), MyImageName , 'Quality', 100)
  1 件のコメント
Anson Hancock
Anson Hancock 2014 年 12 月 9 日
Thanks Orion,
That seems to have done the trick.
Cheers.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by