0

我的 GUI 有问题。在我的打开函数中,我将一个img_new变量定义为我存储的图像。

我的 GUI 有两个轴,一个显示原始图像,另一个显示过滤后的图像。我在带有 4 个单选按钮的面板中有 4 个过滤器。在每个代码的末尾都有img_new= 通过单选按钮过滤器创建的图像。

这是一些代码:

% --- Executes when selected object is changed in uipanel3.
function uipanel3_SelectionChangeFcn(hObject, eventdata, handles)
handles.count = handles.count + 1;

% Change filter orientation depending on which radiobutton is chosen
switch get(eventdata.NewValue,'Tag')
    case 'hte'
        h_te = zeros(handles.rows, handles.colums);

        # code of the filter...

        axes(handles.axes2);
        imshow(h_te);

        handles.img_new = h_te;

    case 'hc'
        h_c = zeros(handles.rows, handles.colums);

        # code of the filter...


        axes(handles.axes2);
        imshow(h_c);

        handles.img_new = h_c;

    case 'vlr'
        v_lr = zeros(handles.rows, handles.colums);

        # code of the filter...


        axes(handles.axes2);
        imshow(v_lr);

        handles.img_new = v_lr;

    case 'vc'
        v_c = zeros(handles.rows, handles.colums);

        # code of the filter...

        axes(handles.axes2);
        imshow(v_c);

        handles.img_new = v_c;

end
guidata(hObject, handles)

这是imwrite功能:

% --------------------------------------------------------------------
function save_img_ClickedCallback(hObject, ~, handles)
% writing the new image
imwrite(handles.img_new, strcat('filtered_image_', num2str(handles.count), '.png'));
guidata(hObject, handles)

这是将图像获取到axes1 原始图像并将其过滤为axes2(已过滤)的功能

% --- Executes on button press in img2.
function img2_Callback(hObject, ~, handles)
% Read image 2
img = imread('./coimbra_estadio.jpg');
handles.img_d = im2double(img);

% image size
size_img = size(handles.img_d);
handles.colums = size_img(2);
handles.rows = size_img(1);

if rem(handles.rows,2) == 0
    handles.row_0 = ((handles.rows/2)+1);
else
    handles.row_0 = ((handles.rows/2)+0.5);
end

if rem(handles.colums,2) == 0
    handles.colum_0 = ((handles.colums/2)+1);
else
    handles.colum_0 = ((handles.colums/2)+0.5);
end

axes(handles.axes1);
imshow(img);

% Generate eventdata to call the radiobuttons function
eventdata_new.EventName = 'SelectionChanged';
eventdata_new.OldValue = get(handles.uipanel3,'SelectedObject');
eventdata_new.NewValue = get(handles.uipanel3,'SelectedObject');

uipanel3_SelectionChangeFcn(handles.uipanel3, eventdata_new, handles);
guidata(hObject, handles)

如您所见,最后我调用了面板函数,因此在加载图像时会自动过滤并axes2更改图像。

问题是当我调用 save 函数时,它会保存旧的img_new.

如果我更改单选按钮,img_new则会刷新,但如果未更改,则不会刷新。它应该像加载图像自动调用单选按钮功能面板一样。

4

1 回答 1

2

问题是guidata(hObject,handles);img2_Callback将旧句柄对象保存为最终 gui 状态时,所做的更新uipanel3_SelectionChangeFcn会丢失。您需要uipannel3_SelectionChangeFcn通过 put handles = guidata(hObject,handles); or调用后手动更新句柄handles=guidata(hObject); (忘记了对 guidata 的哪个调用更新句柄,请参阅帮助),或者只是删除guidata(hObject,handles);img2_callback 末尾的行(如果代码稍后要更改,则安全性较低,更新处理后uipannel3_SelectionChangeFcn是更安全的方法......

于 2012-12-29T18:50:08.300 回答