3

I have an assignment to create a GUI using MATLAB 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 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.

gnovice
  • 125,304
  • 15
  • 256
  • 359
Phizunk
  • 55
  • 1
  • 7
  • The links I gave below pertain to the newest version of MATLAB (2009a). I'm not sure how much has changed since v7.0.1, pertaining to this specific problem. I know IMSHOW was acting slightly different when I ran it in v7.1 versus v7.7. If you could post parts (not all) of your code, perhaps we could help more. – gnovice Apr 20 '09 at 20:52

2 Answers2

4

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.

Community
  • 1
  • 1
gnovice
  • 125,304
  • 15
  • 256
  • 359
  • 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 Apr 20 '09 at 14:56
0

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)
Jason Plank
  • 2,336
  • 5
  • 31
  • 40