saving gray scale images in a 3D array

7 vues (au cours des 30 derniers jours)
Salar
Salar le 21 Fév 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));

Réponses (1)

Cris LaPierre
Cris LaPierre le 9 Avr 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.

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by