saving gray scale images in a 3D array

8 Ansichten (letzte 30 Tage)
Salar
Salar am 21 Feb. 2019
Beantwortet: Cris LaPierre am 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));

Antworten (1)

Cris LaPierre
Cris LaPierre am 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.

Kategorien

Mehr zu Images finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by