How to run m-files automatically ?

Hi,
I have collection of images to analyze using matlab. I made m-file code to analyze one image at a time, but it takes considerable time as there are hundreds of images to run.
Is there anyway to call the files in the folder and run one at a time automatically, without me designating the file name one by one?
Thank you very much for help.

 Akzeptierte Antwort

Matt Fig
Matt Fig am 1 Sep. 2012
Bearbeitet: Matt Fig am 2 Sep. 2012

1 Stimme

D = dir('*.jpg');
for ii = 1:length(D)
% Put your processing code here. Call image names as below...
fprintf('Processing image named %s\n',D(ii).name);
end

5 Kommentare

Taehyung
Taehyung am 2 Sep. 2012
Thank you very much
Image Analyst
Image Analyst am 9 Sep. 2012
Bearbeitet: Image Analyst am 9 Sep. 2012
Why are you using fprintf() inside imread()??? That's just used to write stuff to the command line or a file. Just use D(ii).name in the imread() directly.
fullFileName = fullfile(folder, D(ii).name); % Folder is pwd unless you specify otherwise.
fprintf('About to read in %s...\n', fullFileName);
theImage = imread(fullFileName);
fprintf('Successfully read in %s\n', fullFileName);
Taehyung
Taehyung am 9 Sep. 2012
Thank you for the quick reply. I found what was wrong.
Matt Fig
Matt Fig am 9 Sep. 2012
I am confused. Who is using FPRINTF inside IMREAD?
Image Analyst
Image Analyst am 9 Sep. 2012
Taehyung was but then after I said that, he went back and edited his code to delete it and say "Thank you very much"

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 2 Sep. 2012

1 Stimme

3 Kommentare

Jan
Jan am 2 Sep. 2012
And when you read this section of the FAQ, I suggest to read the rest also.
Jigar Gada
Jigar Gada am 2 Sep. 2012
Bearbeitet: Jigar Gada am 2 Sep. 2012
You could use the foll code
folder_cont = dir('C:\Users\*.jpg');
nsize = size((folder_cont),1);
for i = 1:nsize
str=strcat('C:\Users\',D(i).jpg);
im=imread(str);
%%do the processing of the image here
end
Taehyung
Taehyung am 2 Sep. 2012
Thank you very much for the help!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Images finden Sie in Hilfe-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