Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Please help. don't know what's wrong here.
조회 수: 1 (최근 30일)
이전 댓글 표시
What i want to do is open an image and then by pressing a button to modify it and then display the modified image where the initial image was.But i get this error :
??? Index exceeds matrix dimensions.
Error in ==> Convertor3Dalfa1_0>Genereaza_Callback at 142
img_s(:,:,2)=im_st(:,:,2).*0;
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> Convertor3Dalfa1_0 at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==>
@(hObject,eventdata)Convertor3Dalfa1_0('Genereaza_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
Here is the code:
these are global declarations :
global imagine_st
global imagine_dr
global im_st
global im_dr
global im_finala
global i_st
global i_dr
this is the open image button :
function ImagineSt_Callback(hObject, eventdata, handles)
imagine_st = uigetfile({'*.jpg;*.bmp'});
im_st=imagine_st;
i_st=imagine_st;
axes(handles.AxaImSt);
imshow(im_st);
set(handles.AxaImSt,'Visible','Off')
and this is the button that should modify the image.I tryed to work with another *.m file.
function Genereaza_Callback(hObject, eventdata, handles)
global im_st
rosu(im_st)
The rosu.m file :
function rosu(im_st)
%Reseteaza nuantele GB
img_s(:,:,1)=im_st(:,:,1);
img_s(:,:,2)=im_st(:,:,2).*0;
img_s(:,:,3)=im_st(:,:,3).*0;
axes(AxaImSt);
imshow(img_s);
end
댓글 수: 0
답변 (3개)
Jan
2011년 4월 28일
You have to declare the global variables in each function, you are using them, e.g. by:
global imagine_st imagine_dr im_st im_dr im_finala i_st i_dr
Using GLOBALs to provide data leads to such problems very often. Therefore it would be much more stable to carry the data as inputs and outputs of the functions.
Btw, rosu will fail in the loine "axes(AxaImSt)" also, because "AxaImSt" is not defined.
댓글 수: 1
Walter Roberson
2011년 4월 29일
Your code is assuming that you are getting a truecolor (3D) image, instead of testing that.
But even before that you have a problem: you are applying imshow() and rosu() to the file name instead of to the content of the file. You have not used imread() to read the file.
By the way, your code
img_s(:,:,2)=im_st(:,:,2).*0;
img_s(:,:,3)=im_st(:,:,3).*0;
can be simplified to
img_s(:,:,2:3) = 0;
댓글 수: 0
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!