MATLAB: How to use saveas for binary images

.jpgbinarydicomimagessaveassaveasjpgseparately

Dear all,
I would like to saveas jpg my DICOM images, which I transform to binary images. So I would like to save these binary images. But I only did, that all of these images are in one .jpg picture, but I want to save them separately, for example: binaryImage1.jpg, binaryImage2.jpg,…..binaryImage37.jpg. This is my code:
Folder = 'C:/Users/ced0005/DP/DP_framework/DICOM/slicesCT/';
for i=0;
i = i+1;
for p = 48:86
filename = fullfile(Folder, sprintf('%06d.dcm', p));
grayImage(:,:,1,p - 47)= dicomread(filename);
grayImage_pater(:,:,1,p - 47)= dicomread(filename);
[rows, columns, numberOfColorChannels] = size(grayImage);
if numberOfColorChannels > 1
% Máme barevný obraz, musíme ho převést na černobílý = vybereme zelený kanál

grayImage = grayImage(:, :, 2); % zelený kanál
end
eq_grayImage = histeq(grayImage);%ekvalizace pomocí histogramu obrazu
[rows, columns, numberOfColorChannels] = size(grayImage_pater);
if numberOfColorChannels > 1
% Máme barevný obraz, musíme ho převést na černobílý = vybereme zelený kanál
grayImage_pater = grayImage_pater(:, :, 2); % zelený kanál
end
eq_grayImage_pater = histeq(grayImage_pater);
thresholdValue = 900;
binaryImage_okoli = grayImage > thresholdValue;
% Odstranění okolí.
binaryImage_okoli = imclearborder(binaryImage_okoli);
% Vyplnění otvorů.
binaryImage_okoli = imfill(binaryImage_okoli, 'holes');
% Vymazání menších otvorů.
binaryImage_okoli = bwareaopen(binaryImage_okoli, 750);
%Roztažení binárního obrazu pro přesnější segmentaci
se = strel('line',5,100);
binaryImage_okoli= imdilate(binaryImage_okoli,se);
imshow(binaryImage_okoli, []);
% X(:,:,1,p - 47) = imadjust(X(:,:,1,p - 47),[0 0.022],[]); % increase contrast
saveas(gcf(i),'Binarizace_okoli.png')
end
end
Can you advise me? Thank you for your answers.
Related Question