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

5 vues (au cours des 30 derniers jours)
inter steller
inter steller le 27 Mar 2015
Commenté : Image Analyst le 28 Mar 2015
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???

Réponses (1)

Image Analyst
Image Analyst le 27 Mar 2015
Let us know if you can't.
  2 commentaires
inter steller
inter steller le 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 le 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);

Connectez-vous pour commenter.

Catégories

En savoir plus sur Convert Image Type dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by