Open image in Gui from menu

I am trying to write a simple gui that guides someone through collecting morphometric data from an image. The GUI "works" first time through, but when I want to move on to the next imge, I get errorrs related to handles.ImagesAxis.XLim - but I suspect it is related to a need to reset the image somewhere.
The specific error received was
Unrecognized property 'XLim' for class 'matlab.graphics.primitive.Image'.
Error in NewImTool>Image_Menu_Open_Image_Callback (line 249)
handles.ImageAxis.XLim = [0 m];
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in NewImTool (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)NewImTool('Image_Menu_Open_Image_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating Menu Callback.
Any guidance appreciated.
function Image_Menu_Open_Image_Callback(hObject, eventdata, handles)
% hObject handle to File_Menu_Open_Image (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
h=getImage();
handles.imageFile=h;
I=imread(h);
[m,n]=size(I);
handles.ImageAxis.XLim = [0 m];
handles.ImageAxis.YLim = [0 n];
handles.ImageAxis=imshow(I);
set(handles.info_txt,'String',strcat('File opened is: ',h));
guidata(hObject,handles);

1 comentario

Jan
Jan el 12 de Jun. de 2021
If you mention, that you get "errorrs related to handles.ImagesAxis.XLim", please share the complete messages with us. It is easier to solve a problem than to guess, what the problem is.

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 14 de Jun. de 2021

0 votos

Unrecognized property 'XLim' for class 'matlab.graphics.primitive.Image'.
XLim belongs to the axes. In the line:
handles.ImageAxis=imshow(I)
you store the handle of the image, not of the axes. Maybe you want to change it to:
handles.ImageAxis.XLim = [0 m];
handles.ImageAxis.YLim = [0 n];
handles.Image = imshow(I);

1 comentario

Thomas Miller
Thomas Miller el 14 de Jun. de 2021
Thanks Jan - that seemed to have solved the problem

Iniciar sesión para comentar.

Productos

Versión

R2019b

Preguntada:

el 11 de Jun. de 2021

Comentada:

el 14 de Jun. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by