How to convert selected image to gray scale using MATLAB GUI

1 Ansicht (letzte 30 Tage)
Azhan Lazit
Azhan Lazit am 7 Okt. 2020
Bearbeitet: Mohammad Sami am 7 Okt. 2020
Hye,
Im using MATLAB GUI to select image it n convert it into gray scale And i get n error
Coding in gui
global cim
[filename pathname] = uigetfile({'*.jpg'},'File Selector');
cim = strcat(pathname,filename);
G=rgb2gray(cim)
axes(handles.axes1)
imshow(G)
Error
Error using rgb2gray>parse_inputs (line 80)
MAP must be a m x 3 array.
Error in rgb2gray (line 52)
isRGB = parse_inputs(X);
Error in GUI2>SI_Callback (line 84)
G=rgb2gray(cim)
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in GUI2 (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)GUI2('SI_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.

Antworten (1)

Mohammad Sami
Mohammad Sami am 7 Okt. 2020
Bearbeitet: Mohammad Sami am 7 Okt. 2020
Before you can process the image, you need to load it using imread.
Also it's a bad idea to directly concatenate file paths. For cross platform compatability use fullfile function instead.
cim = fullfile(pathname,filename);
cim = imread(cim);
G=rgb2gray(cim)
axes(handles.axes1)
imshow(G)

Kategorien

Mehr zu Convert Image Type finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by