views:

704

answers:

3

I have an assignment to create a GUI using the matlab built-in gui guide and am having a problem with displaying an edited picture. I need to have buttons that edit the picture (eg. remove red, blue, green components and rotate) and display that edited picture. I am using the imshow() to display the edited picture but it displays in a new window and shuts down the gui I had running. Can anyone help?

  • I've been working on this and have tried numerous different ways of fixing the problem but none worked. However, I am using Matlab 7.0.1, and 7.7.0 might have an update for this problem.
+3  A: 

When you first plot the image with IMSHOW, have it return a handle to the image object it creates:

A = (the initial matrix of image data);
hImage = imshow(A);

Then, to update the image with new data, try the following instead of calling IMSHOW again:

B = (modification of the original image matrix A);
set(hImage,'CData',B);

Using the SET command will change the image object you already created (a list of image object properties can be found here).

Alternatively, you can also add additional parameters to a call to IMSHOW to tell it which axes object to plot the image in:

hAxes = (the handle to an axes object);
imshow(A,'Parent',hAxes);


EDIT: Addressing your additional problem of sharing GUI data between functions, you should check out the MATLAB documentation here. As noted there, there are a few different ways to pass data between different functions involved in a GUI: nesting functions (mentioned on SO here), using the 'UserData' property of objects (mentioned on SO here), or using the functions SETAPPDATA/GETAPPDATA or GUIDATA. The GUIDATA option may be best for use with GUIs made in GUIDE.

gnovice
A: 

The problem I have now is that is doesn't recognize that there is a variable 'hImage.' I think that is because I am trying to edit the picture in a different function in the GUI. How can I carry over the hImage data?

Phizunk
In general, if you have additional problems crop up like this, it's best to edit your original question and add them on instead of adding an answer. Just click the "edit" link below your question. It makes things a bit easier to follow for those reading the questions and answers. =)
gnovice
A: 

The gui m file functions automatically assign the image data to a variable called hObject. Once you have done your image alteration, you have to reassign the new data to hObject:

hObject = imshow(newimagedata)

don't forget to update and save this operation by:

guidata(hObject, handles)

related questions