Grayscale Image cannot be output in the GUI Matlab
이전 댓글 표시
Hi guys, i got a problem here where i want to put my picture into the GUI , and then change the RGB image into grayscale image, but somehow the grayscale image keep getting error and i dont how to fix it. Help please.

Below is the coding that i had write,
[filename,filepath] = uigetfile({'*.*;*.jpg;*.png;*.bmp;*.oct'}, 'Select File to Open');
fullname = imread(strcat(filepath,filename));
app.Image.ImageSource = fullname;
grayImage = rgb2gray(fullname);
app.Image_2.ImageSource = grayImage;
The error that been pop-out is ,
Error using matlab.ui.control.Image/set.ImageSource (line 123)
You have specified an invalid CData.
Valid CData is m-by-n-by-3 truecolor image array.
Thank you in advance
채택된 답변
추가 답변 (1개)
Ali Ridha Ali
2023년 2월 16일
편집: Ali Ridha Ali
2023년 2월 17일
I've faced the same issue, and I got a technical solution by doing a small trick.
You can show grayscale in app.Image component by re-building the grayscale image to be in a 3-channels matrix so that app.Image component can deal with it as an RGB image. This is my code:
GrayImg = rgb2gray(RGBImg);
GrayImg3 = cat(3, GrayImg, GrayImg, GrayImg);
app.Image.ImageSource = GrayImg3;
I tested it, and it works for me :)
I'm showing the trick here in case someone is facing the same problem.
카테고리
도움말 센터 및 File Exchange에서 Images에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

