Save each image loaded by a loop
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (1개)
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.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!