Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build an array of images in Matlab

I'm doing a Matlab project and I need to know how to build an array of images.
I need to have the ability to move through the array in a similar format as a C array with some kind of index.

I tried it with this:

images = [image1 image2 image3 image4 image5];

but I get this error:

CAT arguments dimensions are not consistent.

I checked the size(image) method for every one of the images and all of them are from the same dimension.

What could be wrong or alternatively how I can do this in other way?

thanks.

like image 561
Ofir A. Avatar asked Jun 27 '11 17:06

Ofir A.


People also ask

How do you create an array in MATLAB?

To create an array with four elements in a single row, separate the elements with either a comma ( , ) or a space. This type of array is a row vector. To create a matrix that has multiple rows, separate the rows with semicolons. Another way to create a matrix is to use a function, such as ones , zeros , or rand .

How do you store images in an array?

You have Strings that contain a URI that tells the browser where to find an image. So really, your question is "How to store and access strings in a JavaScript array." Instead of using the Array constructor, use the more common var pictures = [] syntax. Instead of using the square-bracket notation and index, use Array.

How do you display an image matrix in MATLAB?

If you want to see the actual matrix, use disp(I) where I is the image. If you want to view it as an image, use imagesc(I) or imshow(I) . It is important to mention that you need the Image Processing Toolbox to use imshow(I) .


2 Answers

There are two ways you can build an array of images:

1. A 3D array

You catenate your images (all should be the same size) along the third dimension like so:

imgArray=cat(3,image1,image2,image3,...)

You can then access each individual image by indexing the third dimension. E.g.

image1=imgArray(:,:,1);

2. A cell array

In this case, you group your images into a cell array, and each image is contained in its own cell.

imgCell={image1,image2,image3,...};

This is a good choice (the only choice) when your images are of different sizes. To access each individual image, you can index the cell as follows:

image1=imgCell{1};
like image 176
abcd Avatar answered Oct 02 '22 18:10

abcd


This code:

images = [image1 ... image5];

Is functionally equivalent to these statements:

images = horzcat(image1, ..., image5);
images = cat(2, image1, ..., image5);

You get the error because there's at least one dimension in your image[1-5] that is not the same. The only dimension that's allowed to be a different size is the first argument to cat (so in this case the 2nd or columns dimension).

like image 39
syutzy Avatar answered Oct 02 '22 18:10

syutzy