简体   繁体   English

如何在Matlab中创建图像数组

[英]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. 我从目录中逐张读取图像,并希望创建一个图像数组,并将其传递给处理这些图像的mexFunction。 What I am tried so far is not working. 到目前为止,我的尝试无法正常工作。 Let say I have 100 images 256x256 when I do 假设我有100张图片256x256

 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. 每当我这样做时,我都不会得到256x256xn的数组,而是得到了256x(256 * n)的图像,这不是我想要的。 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. 使用单元格数组作为@bjornsen建议的作品。 If you would rather not use cell arrays, you can use 3 dimensional matrices: 如果您不想使用单元格数组,则可以使用3维矩阵:

imageVolume(:,:,idx) = tempImage;

You must be sure, though, that all images are the same size. 但是,您必须确保所有图像的大小均相同。 Otherwise, you're better off using cell arrays. 否则,最好使用单元格数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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