Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read multiple images on a folder in Matlab

I have a problem reading multiple images in Matlab from a folder. I want to read with their original name (with the command imread because are multiband). The names of the images are like '2001_01', '2001_02'. This is my code:

myPath= 'C:\images\'; %'
a=dir(fullfile(myPath,'*.tif'));
fileNames={a.name};

And then...

for k = 1:length(fileNames)
    filename = [fileNames(k).name];  
    I = imread(filename);
end

But it doesn't work and I don't know how to save and imread each one individually. Does somebody know how can I do it? Really thanks in advance,

like image 600
user1578688 Avatar asked Apr 24 '13 11:04

user1578688


1 Answers

  1. Regarding the first problem:

    But it doesn't work...

    Just assign the output of dir directly into fileNames (without brackets):

    fileNames = dir(fullfile(myPath, '*.tif'));
    
  2. Regarding the second problem:

    ... I don't know how to save and imread each one individually.

    it seems that you need a cell array to store all images in a single collection. First, define the cell array to have the right size:

    C = cell(length(fileNames), 1);
    

    and then store each image into a different cell:

    for k = 1:length(fileNames)
        filename = fileNames(k).name;
        C{k} = imread(filename);
    end
    

    To access any image in the cell array C later, use curly braces ({}). For instance, the second image is accessed as follows: C{2}.

like image 182
Eitan T Avatar answered Sep 19 '22 03:09

Eitan T