Save each image loaded by a loop
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I have 4 bmp images named Target1.bmp ..Target4.bmp and I want to load them using a loop. I am using the following code but it is giving me only the data of the last image. How can i adjust it to load all the 4 images and each one store it as separately. Thx
for k = 1:4
filename = strcat('Target', num2str(k),'.bmp');
TargetImg = imread(filename);
end
0 comentarios
Respuestas (1)
Adam
el 11 de Mayo de 2016
Editada: Adam
el 11 de Mayo de 2016
TargetImgs{k} = imread(filename);
will put them in a cell array. If all your images are the same size and you intend to do further analysis across all images it would be much better to store them in a 3d numeric array where the 3d dimension is, in this case, 4, but a cell array is the more generic approach if you can't guarantee the images are all the same size.
You can presize with e.g.
TargetImgs = cell.empty( 0, 4 );
before the loop if you wish, but I'm not sure it makes any real difference with a cell array of just 4 values.
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!