필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Sico
Sico 2017년 3월 28일
댓글: Sico 2017년 3월 28일
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

채택된 답변

Greg
Greg 2017년 3월 28일
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); %

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by