我正在使用Matlab创建一个图像编辑程序。用户在一个按钮回调函数中上传图像。然后,用户可以使用其他按钮回调来编辑图像(旋转,更改为黑色和白色等)。
虽然我可以访问图像,并成功地单独编辑它,但它总是恢复到原始上传状态。例如,如果我先旋转它,然后把它改成黑白,旋转就会消失,反之亦然。
我正在使用:
handles=guidata(hObject);
在每个函数的开头。和
guidata(hObject, handles);
在每个函数的末尾,但函数总是访问最初上传的图像。
如何在每次编辑后成功更新图像句柄??
下面是一个回调函数的例子:function pushbutton3_Callback(hObject, eventdata, handles)
handles=guidata(hObject);
I = rgb2gray(handles.im)
himage = imshow(I, 'Parent', handles.axes1);
guidata(hObject, handles);
当您在一个回调函数中对图像执行操作时,您应该将结果存储回获取图像的handles
结构中。这样,下一次回调函数执行时,它将获得修改后的图像。
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