Read several images to work with

I am trying to read several images (tomographic - grayscale) of an entire volume so I can make some quantifications.
The name of the data changes according to the number of files, e.g.,
image0001 - image0009
image0010 - image0099
image0100 - image0999
and so on...
I have written this code until now (my N is not bigger than 10000):
if N<10
for d = 1:N
s = ['al000' int2str(d) '.bmp'];
end
elseif N>10 && N<100
for d = 1:9
s(d) = ['al000' int2str(d) '.bmp'];
end
for d = 10:N
s(d) = ['al00' int2str(d) '.bmp'];
end
elseif N>100 && N<1000
for d = 1:9
s(d) = ['al000' int2str(d) '.bmp'];
end
for d = 10:99
s(d) = ['al00' int2str(d) '.bmp'];
end
for d = 100:N
s(d) = ['al0' int2str(d) '.bmp'];
end
elseif N>1000 && N<10000
for d = 1:9
s(d) = ['al000' int2str(d) '.bmp'];
end
for d = 10:99
s(d) = ['al00' int2str(d) '.bmp'];
end
for d = 100:999
s(d) = ['al0' int2str(d) '.bmp'];
end
for d = 1000:N
s(d) = ['al' int2str(d) '.bmp'];
end
end
I need to use those names, but there is an error message when I try to use s(d) instead of only s - so I could save all the names I need:
Subscripted assignment dimension mismatch.
Error in teste (line 7) s(d) = ['al000' int2str(d) '.bmp'];
My questions:
1 - How can I save all those names of the images into another variable, which I will need to access all images later?
2 - Is there a easier, faster or, maybe, smarter way to do this if, elseif and for lines? If I had a N even bigger, would I have to write it down for each interval? Or is there a code which would do the same thing I am doing just knowing my N?

Weitere Antworten (1)

David Sanchez
David Sanchez am 14 Aug. 2013

2 Stimmen

base_name = 'a0000.bmp';
s = cell(999,1); % initialize cell to hold names
for k=1:999
tmp_str = num2str(k);
L = length(tmp_str);
base_name(6-L:5) = tmp_str;
s{k} = base_name;
end

4 Kommentare

Haimon
Haimon am 14 Aug. 2013
This one is a very good solution for what I want but a problem came up.
The base name is usually something like "al0000.bmp" There is around 2000~3000 images.
The thing is, the resulting s starts with 'al0010.bmp' instead of 'al0001.bmp'.
Do you know why?
Haimon
Haimon am 14 Aug. 2013
Bearbeitet: Haimon am 14 Aug. 2013
I just found out "7-L:6".
Thank you anyway
Walter Roberson
Walter Roberson am 15 Aug. 2013
The form I used would not have those problems. Just substitute "al" for "image"
Haimon
Haimon am 16 Aug. 2013
I had the problem that my images not always start from 0.
They could start from, e.g., 1689.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by