Image Segmentation and Saving image

1 次查看(过去 30 天)
hello I'm a final year student using Matlab for image segmentation but I have a problem. How do I save multiple pictures automatically? Please help, thank you
image_folder = 'C:\Users\ADMIN\Matlab\Implementasi';
outfolder = 'C:\Users\ADMIN\Matlab\Implementasi\output';
if ~isdir(outfolder); mkdir(outfolder); end
load mri %I presume it has the variable map in it
files = dir(fullfile(image_folder, '*.jpg'));
% filenames = fullfile({fileinfo.folder}, {fileinfo.name});
% total_images = numel(filenames);
for iFiles = 1:numel(files)
thisfilename = fullfile(files(iFiles).folder,files(iFiles).name);
% for n = 1 : total_images
% thisfile = filenames{n};
[~, basename, ext] = fileparts(image_folder);
citra = imread(thisfilename);
V = squeeze(citra);
fprintf('processing %s\n', basename);
citra3 = montage(reshape(V,size(citra)), map, 'Indices', 3);
outfile = fullfile(outfolder, sprintf(['%s-coba-%03d.%s',basename,ext]));
saveas(citra3, outfile);
end

采纳的回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2021-2-25
  2 个评论
Rosida Octavia Sitorua
I have try this from the link which you give but it doesn't create a new folder and save the image to the new folder. Can you tell me why it doesn't work?
Images=dir('C:\input_path\folder_name\*.png'); % Create Folder
outDirectory='C:\out_put_path\out_folder_name\'; % Save Folder
for i=1:length(Images)
ImgName=strcat('C:\C:\input_path\folder_name\',Images(i).name);
In_image=imread(ImgName);
%% Do operation
%Save the image, say result_image
imwrite(result_image,strcat(outDirectory,Images(i).name));
end
KALYAN ACHARJYA
KALYAN ACHARJYA 2021-2-25
Try with this way: Set the Current working directory in Input Folder Path
path_directory='...'; % 'Input Images Folder name Only'
original_files=dir([path_directory '/*.jpg']); % Folder Images in the same Directory
........................................^ Modify as per input images format
folder='output_folder'; % Create Folder to Save Results
for k=1:length(original_files)
filename=[path_directory '/' original_files(k).name];
image_orginal=imread(filename);
%%.Do Operation
result=
fullFileName = fullfile(folder, original_files(k).name);
imwrite(result,fullFileName);
end

请先登录,再进行评论。

更多回答(1 个)

Rosida Octavia Sitorua
I'm sorry but there is error missing extra character in the code namely "result =". Can you tell me what is this mean?
  2 个评论
KALYAN ACHARJYA
KALYAN ACHARJYA 2021-2-28
Oh, this is partial code, the result, I represent the output image, which you want to save. Consider your output image there and change the result variable name accordingly.
Rosida Octavia Sitorua
I want to read all the images in the folder, then segmented and stored in a new folder. But when the segmentation process is only one image running, everybody help me? Thank you very much.
image_folder = 'C:\Users\ADMIN\Matlab\Implementasi';
outfolder = 'C:\Users\ADMIN\Matlab\Implementasi\cobaku';
if ~isdir(outfolder); mkdir(outfolder); end
figure, fig1=imshow(citra);
files = dir(fullfile(image_folder, '*.jpg'))
%change to grayscale
grayimg = rgb2gray(citra);
figure, fig2=imshow(grayimg);
%change to green channel
green_channel = citra(:,:,2);
figure, fig3=imshow(green_channel);
%change to CLAHE (Contrast Limited Adaptive Histogram Equalization)
CLAHE = adapthisteq(green_channel);
figure, fig4=imshow(CLAHE);
ER = edge(CLAHE, 'canny');
EG = edge(CLAHE, 'canny');
EB = edge(CLAHE, 'canny');
anyedge = ER | EG | EB;
figure, fig5=imshow(anyedge)
size(fig5)
load mri %I presume it has the variable map in it
for iFiles = 1:numel(files)
thisfilename = fullfile(files(iFiles).folder,files(iFiles).name);
[~, basename, ext] = fileparts(image_folder);
citra = imread(thisfilename);
V = squeeze(citra);
fprintf('processing %s\n', basename);
fig = figure;
citra3 = montage(reshape(V,size(citra)), map, 'Indices', 3);
outfile = fullfile(outfolder, sprintf('%s-coba-%03d.jpg', basename, iFiles));
saveas(citra3, outfile);
end

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by