How to save multiple output images with same file type as the original input image?

2 ビュー (過去 30 日間)
Tawsif Mostafiz
Tawsif Mostafiz 2021 年 8 月 27 日
回答済み: yanqi liu 2021 年 9 月 27 日
I am taking multiple input images, and doing active contour segmentation like this:
[B,L]=bwboundaries(tumor,'noholes'); %draw boundaries around the tumor and no holes needed.
for i=1:length(B)
rows, columns, numberOfColorChannels] = size(imageArray);
mask = poly2mask(B{i}(:,2),B{i}(:,1), rows, columns);
end
B0=mask;
img1=activecontour(imageArray,B0,iteration,'edge');
Now, I want to save img1, which is a biinary image, as the same file extension as the original image. If the original image is in png, I want the mask also to be png.
In am using the following to save output,
path = myFolder; % mention your path
myfolder = 'Segmented Pictures' ; % new folder name
folder = mkdir([path,filesep,myfolder]) ;
path = [path,filesep,myfolder] ;
temp=[path,filesep,baseFileName,'.png'];
saveas(gca,temp);
But here, I have to select the output image type (here it is .png) and the output is like this, with white borders all around(like the output figure in matlab),
I want to input multiple images and want to save the output images in a selected folder, similar like the code above. The output images should look like this(This is not mask for another image):
How do I do it?

回答 (1 件)

yanqi liu
yanqi liu 2021 年 9 月 27 日
sir,please check the follow code to get some information
[~,~,filetype] = fileparts('youfile.jpg')
filetype = '.jpg'
clc; clear all; close all;
im = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/723174/image.png');
im = im2bw(im);
figure; imshow(im)
im = imclearborder(im);
figure; imshow(im)

カテゴリ

Help Center および File ExchangeAgriculture についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by