简体   繁体   中英

How do I create an array of image in matlab

I read one by one images from a directory and I wish to create an array of images with that to pass to my mexFunction that processes these images. What I am tried so far is not working. Let say I have 100 images 256x256 when I do

 directory = uigetdir; fileList = dir(directory); imageVolume= [];

for idx = 3:numel(fileList)

     tempImage = imread(fullfile(directory, fileList(idx).name));
    imageVolume= [imageVolume tempImage]; 
 end

Whenever I do that, I don't get an array of 256x256xn, instead I just get an image of 256x(256*n), which is not what I want. Any idea?

Use Cell Arrays. Assuming the rest of your code is right:

for idx = 3:numel(fileList)
     tempImage{idx} = imread(fullfile(directory, fileList(idx).name));
end

Using cell arrays as @bjornsen suggested works. If you would rather not use cell arrays, you can use 3 dimensional matrices:

imageVolume(:,:,idx) = tempImage;

You must be sure, though, that all images are the same size. Otherwise, you're better off using cell arrays.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM