Effacer les filtres
Effacer les filtres

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)
Quick Click
Quick Click le 28 Avr 2011
Clôturé : MATLAB Answer Bot le 20 Août 2021
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

Réponses (3)

Jan
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
Quick Click
Quick Click le 29 Avr 2011
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 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;

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

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by