How to save all figure as jpeg format in folder?

srcFiles = dir('C:\Users\fit\Documents\MATLAB\H\*.jpg'); % the folder in which ur images exists
for i = 1 : length(srcFiles)
filename = strcat('C:\Users\fit\Documents\MATLAB\H\',srcFiles(i).name);
I = imread(filename);
I = rgb2gray(I);
I = im2double(I);
origin = I;
regions = detectMSERFeatures(I);
figure; imshow(I); hold on; plot(regions, 'showPixelList', true, 'showEllipses', false);
end
saveas(figurename,' C:\Users\fit\Documents\MATLAB\H'.'jpg')

Answers (1)

Image Analyst
Image Analyst on 11 Mar 2017
Edited: Image Analyst on 11 Mar 2017

3 Comments

Thanks System Analyst, how to save all figures? My problem is I only can save ONE figures in jpg format.
srcFiles = dir('C:\Users\fit\Downloads\Code\altmany-export_fig-2763b78\altmany-export_fig-2763b78\Arabian_Horses\*.jpg'); % the folder in which ur images exists
for i = 1 : length(srcFiles)
filename = strcat('C:\Users\fit\Downloads\Code\altmany-export_fig-2763b78\altmany-export_fig-2763b78\Arabian_Horses\',srcFiles(i).name);
I = imread(filename);
I = rgb2gray(I);
I = im2double(I);
origin = I;
regions = detectMSERFeatures(I);
f=figure(); imshow(I,'Border','tight'); hold on; plot(regions, 'showPixelList', true, 'showEllipses', false);
export_fig(f, filename,'jpg')
end
Check your filename - is it different each time? Maybe put this after imshow():
drawnow;
Maybe also try closing the figure after you save it
close(f);
Thanks Image Analyst, I was solve my problem. Here it is. Dear Image Analyst, how to automatically crop out the MSER region area and paste in figure?
srcFiles = dir('C:\Users\fit\Downloads\Code\export figure\Arabian_Horses\*.jpg'); % the folder in which ur images exists
for i = 1 : length(srcFiles)
filename = strcat('C:\Users\fit\Downloads\Code\export figure\Arabian_Horses\',srcFiles(i).name);
I = imread(filename);
I = rgb2gray(I);
I = im2double(I);
origin = I;
regions = detectMSERFeatures(I);
f=figure(); imshow(I,'Border','tight'); hold on; plot(regions, 'showPixelList', true, 'showEllipses', false);
export_fig (sprintf('figure%d',i),'-jpg');
end

Sign in to comment.

Tags

Asked:

on 11 Mar 2017

Edited:

on 13 Mar 2017

Community Treasure Hunt

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

Start Hunting!