Grayscale Image cannot be output in the GUI Matlab
Ältere Kommentare anzeigen
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
Akzeptierte Antwort
Weitere Antworten (1)
Ali Ridha Ali
am 16 Feb. 2023
Bearbeitet: Ali Ridha Ali
am 17 Feb. 2023
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.
Kategorien
Mehr zu Develop Apps Using App Designer finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

