フィルターのクリア

How can I use a loop to save the output image of the program after each iteration?

4 ビュー (過去 30 日間)
for slice = 1:16
recon_img = senserecon(aliased_img, sen_map,reduc, fi_matrix);
figure;imshow(abs(recon_img),[0 0.000005]);
end
The code is big. So, I just mentioned the loop for the number of iterations here. Here, there will be 16 output images. How can I save all output images using a loop?
  1 件のコメント
Image Analyst
Image Analyst 2022 年 3 月 16 日
By "output image" do you mean you want to save the variable recon_img in a file with a standard image format like PNG? Or do you want to save the figure, which would contain the image, tick marks, tick labels, the surrounding frame between the axes and the edge of the figure, any graphics that might have been drawn on the image, etc.? If you want the whole figure, use exportgraphics(). If you want just the image variable use imwrite() like I show you below in my answer.

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

採用された回答

Image Analyst
Image Analyst 2022 年 3 月 15 日
It's probably a floating point image. Try converting it to uint8 before saving it.
outputFolder = pwd; % Wherever you want.
for slice = 1:16
recon_img = senserecon(aliased_img, sen_map,reduc, fi_matrix);
subplot(4, 4, slice);
uint8Image = uint8(255 * mat2gray(abs(recon_img)));
imshow(uint8Image, []);
drawnow;
baseFileName = sprintf('Image Slice %d.png', slice);
outputFileName = fullfile(outputFolder, baseFileName);
imwrite(uint8Image, outputFileName)
end

その他の回答 (2 件)

Voss
Voss 2022 年 3 月 15 日
for slice = 1:16
recon_img = senserecon(aliased_img, sen_map,reduc, fi_matrix);
imwrite(recon_img,sprintf('image_slice_%03d.png',slice)); % write recon_img to file
figure;imshow(abs(recon_img),[0 0.000005]);
end
  3 件のコメント
Voss
Voss 2022 年 3 月 15 日
編集済み: Voss 2022 年 3 月 15 日
Try experimenting with different options in imwrite().
If I had one of your images, I might be able to offer more specific advice.
Gulfam Saju
Gulfam Saju 2022 年 3 月 15 日
print(gcf,'-dpng','-r200','sense_rec', slice);
when I use this, it perfectly works. But, I don't know how to run a loop on it.

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


yanqi liu
yanqi liu 2022 年 3 月 16 日
for slice = 1:16
recon_img = senserecon(aliased_img, sen_map,reduc, fi_matrix);
figure;imshow(abs(recon_img),[0 0.000005]);
print(gcf,'-dpng','-r200',sprintf('sense_rec%02d', slice));
end

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by