Filter löschen
Filter löschen

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

3 Ansichten (letzte 30 Tage)
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???

Antworten (1)

Image Analyst
Image Analyst am 27 Mär. 2015
Let us know if you can't.
  2 Kommentare
inter steller
inter steller am 28 Mär. 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 am 28 Mär. 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);

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Convert Image Type finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by