pizzaEatingGuy
pizzaEatingGuy

Reputation: 888

How do I create an array in matlab consisting of multiple 3d imagedata arrays

I have 15 images that I am reading using imagedata = imread('imagename.jpg') its size is always 320 by 320 by 3

How do I put the data in an array (using a for for loop) such that when I access the first element of the new array I get the RGB data of the first image I input?

Upvotes: 2

Views: 54

Answers (2)

Luis Mendo
Luis Mendo

Reputation: 112669

Since all images have the same size, it may be more efficient to use a 4D array than a cell array:

imArray = NaN(320,320,3,15);
for n = 1:15
    imArray(:,:,:,n) = imread(filename); %// filename should probably change
end

You can then access the first image as imArray(:,:,:,1), etc.

Upvotes: 2

Rash
Rash

Reputation: 4336

You should probably use cell

imCell = {};
for i = 1 :15
    imCell{i} = imread(num2str(something));
end

And you could easily have access,

for j = 1 : 15
    subplot(5,3,j);
    imshow(imCell{j});
end

imCell is a cell with size 1x15. However imCell{i} is an arrey with size 320x320x3.

Using cell will allow you to even save arrays of different sizes in it.

Upvotes: 3

Related Questions