How to open multiple images, processing each image, then saving it into a folder?

2 views (last 30 days)
My code is as below,
file = dir('C:\Users\doey\Desktop\New folder');
file = file(~[file.isdir]); NF = length(file);
for k = 1 : NF
Img = imread(fullfile('C:\Users\doey\Desktop\New folder', file(k).name));
% Processing the image
% Obtain figure(k)
print(figure(k),'-dpng','C:\Users\doey\Desktop\New folder (2)')
close(gcf)
end
Can anyone answer these 2 questions:
1) The figures which I obtain are not saving in my directory (C:\Users\doey\Desktop\New folder) although I can show it during my processing.
2) I cannot load tiff images with this code. Why not???

Answers (1)

Image Analyst
Image Analyst on 27 Mar 2015
Let us know if you can't.
  2 Comments
inter steller
inter steller on 28 Mar 2015
i can read the file now , but why i still can't save my figure? as the code above , after i done my image processing for multiple images, i were plotted something for every image, and i need to auto-save them into a folder.
Image Analyst
Image Analyst on 28 Mar 2015
Like the FAQ says, create your filename using sprintf() and fullfile(). Then you just call imwrite(yourImage, fullFileName) to write it out to a disk file in the folder. If you want to write the whole figure or axes, because you have put up some graphical overlay onto the image, then use export_fig() instead.
You're using print() instead, which might be okay, but you're just giving it a folder name and not a filename. Try constructing a filename:
fullFileName = fullfile('C:\Users\doey\Desktop\New folder', file(k).name)
[folder, fn, ext] = fileparts(fullFileName);
% Change extension to .png.
fn = sprintf('%s.png', fn);
% Prepend folder
fullFileName = fullfile(folder, fn);
% Save to disk.
print(figure(k), fullFileName);

Sign in to comment.

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!