Load picture from folder

I have write a code to load some pictures from special folder, unfortunately just load last picture.
The picture name is initially started from B19111 to finish B191110, according to this "*B-1911-k*" numbering .
for a=1:10
b=num2str(a);
B{a}=imread(strcat('B1911',num2str(b),'.tif'));
end
My questions: 1. The reason of error. 2. Why the B{a} in workspace show the info of picture?
thanks

1 comentario

Romendra
Romendra el 26 de Sept. de 2012
That is because B{} is a cell rather than a matrix. If you access the first part of the cell by B{1} it should show you the matrix associated with your image. As for the error what is the msg saying?
Thanks

Iniciar sesión para comentar.

Respuestas (3)

Image Analyst
Image Analyst el 26 de Sept. de 2012
Editada: Image Analyst el 28 de Sept. de 2012

0 votos

See the examples from the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F. It does what you want to do. Here it is, slightly adapted for your situation:
% Read tiff files B19111.jpg through B191110.jpg.
folder = 'c:\whatever'; % Folder where your files live. Could be pwd if they are in the current folder.
for k = 1 : 10
imageFilename = sprintf('B1911%d.tif', k);
fullFileName = fullfile(folder, imageFilename);
if exist(fullFileName , 'file')
fprintf('Processing image %s\n', fullFileName);
imageArray{k} = imread(fullFileName);
else
fprintf('Image %s does not exist!\n', fullFileName);
end
end
Azzi Abdelmalek
Azzi Abdelmalek el 26 de Sept. de 2012

0 votos

for a=1:10
out{a}=imread(sprintf('B1911%d.tif',a))
end

3 comentarios

ibleteus
ibleteus el 28 de Sept. de 2012
In my code i use "strcat('B1911','num2str(b)','.tif')" to string number to replace 1 by 1 instead of 'num2str' from 1:10. when i run this code just give me a cell, when i use your recommend i have such this problem and just give me first picture.
Azzi Abdelmalek
Azzi Abdelmalek el 28 de Sept. de 2012
Editada: Azzi Abdelmalek el 28 de Sept. de 2012
clear out
for k=1:10
out{k}=imread(sprintf('B1911%d.tif',k))
figure
imshow(out{k})
end
Image Analyst
Image Analyst el 28 de Sept. de 2012
You did something wrong. 'num2str(b)' should not be in quotes. But sprintf() is a better way than strcat() in my opinion. Have you looked at the FAQ? I adapted the code in there and posted it above for you in case you had difficulty doing that.

Iniciar sesión para comentar.

Walter Roberson
Walter Roberson el 26 de Sept. de 2012

0 votos

Your code has
b = num2str(a);
and then in the next line uses num2str(b), thus trying to convert to string something that is already a string. The second line should use b instead of num2str(b)

Categorías

Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.

Preguntada:

el 24 de Sept. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by