Info

此问题已关闭。 请重新打开它进行编辑或回答。

Please help. don't know what's wrong here.

1 次查看(过去 30 天)
Quick Click
Quick Click 2011-4-28
关闭: MATLAB Answer Bot 2021-8-20
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

回答(3 个)

Jan
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 个评论
Quick Click
Quick Click 2011-4-29
hey,
thanks for the very fast answer.
i did what you suggested( i declared all the globals in the functions i used them) and i also replaced
axes(AxaImSt);
imshow(img_s);
in rosu.m with
figure
imshow(img_r)
but i still get the same error.

Walter Roberson
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;

Quick Click
Quick Click 2011-5-8
Hey guys, Just wanted to thank you. Both answers really helped me.

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by