Effacer les filtres
Effacer les filtres

Reading an image on an axes and manipulate it then display it on another axes

1 vue (au cours des 30 derniers jours)
Sico
Sico le 28 Mar 2017
Commenté : Sico le 28 Mar 2017
Hie guys I have this code below. I want to read an image on axes1 then extract the green channel and then display on axes 2. How can I go about it. Thank you in advance.
% --- Executes on button press in img_load.
function img_load_Callback(hObject, eventdata, handles)
[filen, pathn] = uigetfile(' *.jpg;*.bmp','select an input image');
I = imread([pathn,filen]); %loading an image
if ndims(I) == 3 %Number of array dimensions
I1 = rgb2gray(I); %conversion of the color image into gray image
else
I1 = I;
end
I1 = imresize(I1,.5); % resizing the size of the image to fit in the axes
axes(handles.axes1); %instructing axes to handle the loaded image
image(I1);
setappdata(0,'image',I1); %
imshow(I1)
title(filen);
% --- Executes on button press in green_channel.
function green_channel_Callback(hObject, eventdata, handles)
I3=getappdata(0,'image');
green = I3(:,:,2); % Green channel
a = zeros(size(I3, 1), size(I3, 2));
just_green = cat(3, a, green, a);
axes(handles.axes2);
imshow(I3)
axes, imshow(just_green), title('Green channel')
image(I3);
I'm getting the following errors
Index exceeds matrix dimensions.
Error in diagnosis>green_channel_Callback (line 108) green = I2(:,:,2); % Green channel
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in diagnosis (line 42) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)diagnosis('green_channel_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback

Réponse acceptée

Greg
Greg le 28 Mar 2017
You're setting the grayscale image as the appdata. This doesn't have a third dimension to index into.
Replace
setappdata(0,'image',I1); %
with
setappdata(0,'image',I); %

Plus de réponses (0)

Catégories

En savoir plus sur Convert Image Type dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by