displaying Images from image array

조회 수: 6 (최근 30일)
Vivek Raj
Vivek Raj 2023년 3월 29일
이동: DGM 2023년 5월 29일
I have 35 gray images which is stored in "gray" variable. I want to display all these images using imshow one by one. The problem is I am getting error.
Gray variable size =35*1080*1920
imshow(Gray(1:1,:,:))
Error using images.internal.imageDisplayValidateParams>validateCData
Multi-plane image inputs must be RGB images of size MxNx3.
Error in images.internal.imageDisplayValidateParams (line 30)
common_args.CData = validateCData(common_args.CData,image_type);
Error in images.internal.imageDisplayParseInputs (line 79)
common_args = images.internal.imageDisplayValidateParams(common_args);
Error in imshow (line 253)
images.internal.imageDisplayParseInputs({'Parent','Border','Reduce'},preparsed_varargin{:});

답변 (2개)

Dyuman Joshi
Dyuman Joshi 2023년 3월 30일
이동: DGM 2023년 5월 29일
Maybe size is the problem, try reshaping the size of the array and then using imshow()
in=rand(35,1080,1920);
out=in(1,:,:);
size(out)
ans = 1×3
1 1080 1920
out=permute(out,[2 3 1]);
size(out)
ans = 1×2
1080 1920
imshow(out)
  댓글 수: 2
Vivek Raj
Vivek Raj 2023년 3월 31일
이동: DGM 2023년 5월 29일
Thanks a lot but for curiosity if i am writing
out=in(1,:,:);% just to know the difference between 1*1080*1920 and 1080*1920 and why its not working
imshow(out)
Dyuman Joshi
Dyuman Joshi 2023년 3월 31일
이동: DGM 2023년 5월 29일
The difference is that 1x1080x1920 is a 3D array whereas 1080x1920 is a 2D array.
As to why it's not working - A grayscale image is expected to be a 2D matrix.

댓글을 달려면 로그인하십시오.


Aman
Aman 2023년 5월 29일
Hi,
As per my understanding, you have an array of grayscale images, and you want to show all of them in a single plot.
The 'Gray' variable has a size of 35*1080*1920, which means it has an image of length 35, width 1080, and number of channels 1920; it doesn’t mean 35 grayscale images of size 1080*1920. You can store the grayscale images in the cell array, and then you can use the ‘subplot' method to plot all of them in a single plot. You can look at the below code for reference.
img = imread("dummy.png");
Gray{1} = rgb2gray(img);
Gray{2} = rgb2gray(img);
Gray{3} = rgb2gray(img);
Gray{4} = rgb2gray(img);
subplot(2,2,1);
imshow(Gray{1});
subplot(2,2,2);
imshow(Gray{2});
subplot(2,2,3);
imshow(Gray{3});
subplot(2,2,4);
imshow(Gray{4});
Hope it helps!

카테고리

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