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,
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'));
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}
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With