saving gray scale images in a 3D array

조회 수: 7 (최근 30일)
Salar
Salar 2019년 2월 21일
답변: Cris LaPierre 2019년 4월 9일
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));

답변 (1개)

Cris LaPierre
Cris LaPierre 2019년 4월 9일
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.

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by