Info
Cette question est clôturée. Rouvrir pour modifier ou répondre.
Please help. don't know what's wrong here.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (3)
Jan
le 28 Avr 2011
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 commentaire
Walter Roberson
le 29 Avr 2011
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 commentaires
Cette question est clôturée.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!