Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top