HOW TO SAVE IMAGES FROM SUBPLOT TO PNG?

조회 수: 19(최근 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