Maggie
Maggie

Reputation: 33

Writing an array of images

I want to create an array of images in MATLAB (images in 2D uint8 array form). I want to use them for writing .jpg files, or for imshow (Basically accessing each 2D from a 3D integer array). I am not able to use them for either purpose. Please help. Here's a sample code:

for k =1:no_images
    for i=1:Height
        for j=1:Width
            image(k,i,j) = uint8( k+i+j ) ;
        end
    end
    imshow( image(k) );
end

Upvotes: 0

Views: 210

Answers (3)

Jalal Aghazadeh
Jalal Aghazadeh

Reputation: 65

this may help:

img = cell(m, n);
img{i, j} = Image;

Upvotes: 1

Vuwox
Vuwox

Reputation: 2359

This will to the job.

Img = image(k,:,:);
imshow(Img);

EDIT

As a 3D array like this, you only have grayscale image, but if you have a 4D array that contain your color channel it's the same.

Img = image(k,:,:,:);
imshow(Img);

EDIT2

Before the image your image is 1xHeightxWidth, so you just need to do

Img = reshape(Img,[Height Width]); 

Upvotes: 2

user2041376
user2041376

Reputation:

You probably mean that you want to preallocate memory for these images, because imshow only presents them , and image(k,i,j) = uint8( k+i+j ) just writes a number into each pixel of the 3D array accorsing to the loop (doesn't make sense)

just use

 image=zeros(N,M,L,'uint8');

where N,M,L are the 3-D dimensions, to create a 3D array of zeros. then image(:,:,n)=... will assign the n-th image into the array.

Upvotes: 1

Related Questions