Question

I'm creating an Image Editing Program using Matlab. The user uploads the image in one pushbutton callback function. The user can then use other pushbutton callbacks to edit the image (rotate, change into black and white etc).

Whilst I can access the image, and successfully edit it individually, it always reverts back to its original uploaded state. For example - if I were to rotate it first, then change to black and white the rotation would disappear and vice versa.

I am using:

handles=guidata(hObject); 

at the beginning of every function. And

guidata(hObject, handles);

at the end of every function, but the functions always access the originally uploaded image.

How can I successfully update the image handle after every edit???

Here is an example of a callback function:

function pushbutton3_Callback(hObject, eventdata, handles)
handles=guidata(hObject);
I = rgb2gray(handles.im)
himage = imshow(I, 'Parent', handles.axes1);
guidata(hObject, handles);
Was it helpful?

Solution

When you perform an operation on the image in one the callback functions, you should store the result back in the handles structure where you obtained the image. That way the next time a callback function executes, it will obtain the modified image.

function pushbutton3_Callback(hObject, eventdata, handles)
    %# get the image from the handles structure
    img = handles.im;

    %# process the image in some way and show the result
    img = rgb2gray(img);
    himage = imshow(img, 'Parent', handles.axes1);

    %# store the image back in the structure
    handles.im = img;
    guidata(hObject, handles);
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top