HOW TO SAVE IMAGES FROM SUBPLOT TO PNG?

9 vues (au cours des 30 derniers jours)
mohd akmal masud
mohd akmal masud le 7 Oct 2021
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.

Réponse acceptée

Walter Roberson
Walter Roberson le 7 Oct 2021
%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 commentaire
mohd akmal masud
mohd akmal masud le 7 Oct 2021
its WORK!!!! TQ VERY MUCH WALTER

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by