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

3 次查看(过去 30 天)
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???

回答(1 个)

Image Analyst
Image Analyst 2015-3-27
Let us know if you can't.
  2 个评论
inter steller
inter steller 2015-3-28
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 2015-3-28
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);

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by