Reputation: 33
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
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
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