-2

I have folder containing thousands of (*.jpg) images inside and would like to loop over the name of them and apply calculations on them.

has anybody kind of loop in mind for this?

Muhammad Muazzam
  • 2,810
  • 6
  • 33
  • 62

2 Answers2

0

Loop over the variables that are determining your filenames and use sprintf() to format those variables into strings.

I can't quite figure out your filename pattern, but you would read the first group like this, for example:

for i = 0:9

    % The %d character will be replaced by i in the string
    filename = sprintf('abcda0b%d99.jpg',i);
    im = imread(filename);

    % Image calculations

end

If your filenames obey a single pattern, you can do this with nested loops to construct the filename from the variables that are determining your filename. If you reply with more detail about your naming pattern I can help you out.

swjm
  • 46
  • 5
  • yes , sure. The names patterns are like the following : abcd_a0b0.jpg, abcd_a0b99.jpg, abcd_a0b199.jpg, ...abcd_a0b9899.jpg,abcd_a0b9999.jpg, abcd_a0b1009.jpg, ...abcd_a0b1289.jpg. – Setareh Mdghlch Jan 22 '17 at 10:56
  • yes , sure. The names patterns are like the following : abcd_a0b0.jpg, abcd_a0b99.jpg, abcd_a0b199.jpg, ...abcd_a0b9899.jpg,abcd_a0b9999.jpg, abcd_a0b1009.jpg, ...abcd_a0b1289.jpg. Then the new naming starts as followed: abcd_a99b0.jpg, abcd_a99b99.jpg, abcd_a99b199.jpg, ...abcd_a99b12799.jpg. Then the new naming set abcd_a199b0.jpg , abcd_a99b199.jpg, abcd_a99b299.jpg, ... and the last on comes to abcd_a18399b12799.jpg. The names are assigned during the scanning of image and the name are coordinates of every scanned point. – Setareh Mdghlch Jan 22 '17 at 11:02
0

You can use dir function:

path='The_path_to_directory_contains_the_jpg_files';
d=dir(path);

for k=3:length(d)
    im=imread(fullfile(path,d(k).name));
    % do calculations
end
Adiel
  • 3,071
  • 15
  • 21