Navack
Navack

Reputation: 3

Display "imshow" images in a GUI using GUIDE

I have a piece of code that is 300 lines long. There is 3 different instances of imshow throughout the code that displays figures as the code is run.. The GUI I am creating will be very simple. Currently I have a push button that initiates the m file. I am trying to get the images to be displayed within the GUI that I am creating and not in separate Figure windows. I have being looking at tutorials online but cant get a quick fix for my problem, they all get a bit convoluted and I cant figure out what exactly to do.

I have 3 axis inserted onto the GUI, In the "view callbacks" for each axis I can createfcn, deletefcn and buttonDownFcn. When I createFcn it gives me a hint to "place code in OpeningFcn to populate axes1" in the auto generated code.

I have tried to do this but I am not able to find the correct place to write the code.

Can somebody tell me if I am going in the correct direction or if I have it wrong.

Thanks

Upvotes: 0

Views: 21334

Answers (2)

Huguenot
Huguenot

Reputation: 2447

In order to display these images, you need to declare the parent in imshow. The parent is what you want to act as the canvas for your image, and in your case will be an axes.

I created a very simple gui with three axes and a push button. MATLAB named my axes axes1, axes2 and axes3. Guide saves the handles to these axes so that you can interact with them throughout your gui code. For example, you mentioned the opening function... here is mine with a call to imshow (the only lines I added were the last three ones):

% --- Executes just before myGUI is made visible.
function myGUI_OpeningFcn(hObject, eventdata, handles, varargin)

% Choose default command line output for myGUI
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes myGUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);
imshow('myImage1.png', 'Parent', handles.axes1)
imshow('myImage2.png', 'Parent', handles.axes2)
imshow('myImage3.png', 'Parent', handles.axes3)

Notice that I can grab the handles of my axes and then declare them to be the parents for the results of my imshow call.

If you're not sure what the names of your handles are, you can check in the GUI editor by right clicking, looking at the property inspector, and the tag property.

If you want to perform a similar operation for when you click on your pushbutton, right click on the button in the editor, and click on View Callbacks -> Callback, and you can add your imshow code there.

Good luck.

Upvotes: 2

David Hassan
David Hassan

Reputation: 155

If I understand correctly you just want your images to appear in the axes instead of a figure. Try setting the focus to the axes itself before showing the image.

    axes(1);%you may need to change the one to your axes handle. 
    imagesc(imageToBeDisplayed);

    axes(2);
    imagesc(secondImage);

    axes(3);
    imagesc(thirdImage);

This way before you call imagesc you make sure your program knows where to send the image. Otherwise it may just create a figure.

Upvotes: 1

Related Questions