MATLAB Answers

Salar
0

saving gray scale images in a 3D array

Asked by Salar
on 21 Feb 2019
Latest activity Answered by Cris LaPierre on 9 Apr 2019
I want to save 4 gray scale images in a 3D array and use them. I wrote the following code for this purpose but it did not work!
object_dataset1(:,:,1)=rgb2gray(imread('object1_1.jpg'));
object_dataset1(:,:,2)=rgb2gray(imread('object1_2.jpg'));
object_dataset1(:,:,3)=rgb2gray(imread('object1_3.jpg'));
object_dataset1(:,:,4)=rgb2gray(imread('object1_4.jpg'));
when I use the imshow function to show one of the images it show a white surface!!
for example : imshow(object_dataset1(:,:,2));

  0 Comments

Sign in to comment.

1 Answer

Answer by Cris LaPierre on 9 Apr 2019

Not sure. It works for me.
Check that all your images have the exact same dimensions.
Also, sanity check your code. What happens when you run this?
img = imread('object1_1.jpg')
imshow(img)
img_gr = rgb2gray(imread('object1_1.jpg'))
figure
imshow(img_gr)
object_dataset1(:,:,1)=rgb2gray(imread('object1_1.jpg'));
object_dataset1(:,:,2)=rgb2gray(imread('object1_1.jpg'));
object_dataset1(:,:,3)=rgb2gray(imread('object1_1.jpg'));
object_dataset1(:,:,4)=rgb2gray(imread('object1_1.jpg'));
figure
imshow(object_dataset1(:,:,1))
Note that this actual line of code won't run:
for example : imshow(object_dataset1(:,:,2))
I assume that is just a copy/paste error since otherwise you'd be reporting an error message instead of a white image.

  0 Comments

Sign in to comment.