HOW TO SAVE IMAGES FROM SUBPLOT TO PNG?

16 ビュー (過去 30 日間)
mohd akmal masud
mohd akmal masud 2021 年 10 月 7 日
コメント済み: mohd akmal masud 2021 年 10 月 7 日
Hi all,
I have 41 images. when I binarize it, then I plot 41 images in one figure as shown below. My coding as below. How to extract it into their own. I mean I want to save as png. Im used imwrite but failed.
%testimages
DATASetDir = fullfile('C:\Users\Akmal\Desktop\I-131 256 28.02.2020\I-131 SPECT NEMA VALIDATION 01112019 256X256 26.09.2021 petang');
IMAGEDir = fullfile(DATASetDir,'Test');
IMDS = imageDatastore(IMAGEDir);
% IMDS = imageDatastore(IMAGEDir , ...
% 'FileExtensions', '.dcm','ReadFcn',@(x) dicomread(x));
% % volReader = @(x) dicomRead(x);
% voldsTest = imageDatastore(IMAGEDir , ...
% 'FileExtensions','.dcm','ReadFcn',volReader);
alldice=[]
acc=[]
for ii=1:41
subplot(6,7,ii)
I = readimage(IMDS,ii);
[C,scores] = semanticseg(I,net1);
B = labeloverlay(I,C);
outt2=C=="foreground";
st2=strel('disk',5);
outt22=imopen(outt2,st2);
title('input')
imshow(outt22)
end
for k = 1:41
imwrite(outt22(:,:,k), sprintf('%d.png', k));
end
this is my error
Index in position 3 exceeds array bounds (must not exceed 1).
only first image saved, the rest 40 image not have.
ANYONE CAN HELP ME? SHOULD BE CAN SAVE 41 IMAGES BINARY IMAGES.

採用された回答

Walter Roberson
Walter Roberson 2021 年 10 月 7 日
%testimages
DATASetDir = fullfile('C:\Users\Akmal\Desktop\I-131 256 28.02.2020\I-131 SPECT NEMA VALIDATION 01112019 256X256 26.09.2021 petang');
IMAGEDir = fullfile(DATASetDir,'Test');
IMDS = imageDatastore(IMAGEDir);
% IMDS = imageDatastore(IMAGEDir , ...
% 'FileExtensions', '.dcm','ReadFcn',@(x) dicomread(x));
% % volReader = @(x) dicomRead(x);
% voldsTest = imageDatastore(IMAGEDir , ...
% 'FileExtensions','.dcm','ReadFcn',volReader);
alldice=[]
acc=[]
for ii=1:41
subplot(6,7,ii)
I = readimage(IMDS,ii);
[C,scores] = semanticseg(I,net1);
B = labeloverlay(I,C);
outt2=C=="foreground";
st2=strel('disk',5);
outt22(:,:,ii) = imopen(outt2,st2);
title('input')
imshow(outt22(:,:,ii))
end
for k = 1:41
imwrite(outt22(:,:,k), sprintf('%d.png', k));
end
However... why do you bother to do the labeloverlay() when you do not use B after that? The image you save is of the imopen() of the binary result about whether C predicted foreground or not.
  1 件のコメント
mohd akmal masud
mohd akmal masud 2021 年 10 月 7 日
its WORK!!!! TQ VERY MUCH WALTER

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by