Save each image loaded by a loop

1 回表示 (過去 30 日間)
MF
MF 2016 年 5 月 11 日
編集済み: Adam 2016 年 5 月 11 日
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

回答 (1 件)

Adam
Adam 2016 年 5 月 11 日
編集済み: Adam 2016 年 5 月 11 日
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.

カテゴリ

Help Center および File ExchangeGet Started with Image Processing Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by