在MATLAB中的同一GUI中更新数据 [英] updating data within same GUI in MATLAB

查看:317
本文介绍了在MATLAB中的同一GUI中更新数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MATLAB中创建了一个图像编辑器窗口,其中包括各种操作,包括亮度,对比度,裁切,旋转等.在此GUI中,每个操作都有其自己的函数回调.

I've created one image editor window in MATLAB, which includes various operations including brightness, contrast, crop, rotate etc.., In this GUI, each operations has its own function call backs.

我的问题是链接一个功能和另一个功能.如果我裁剪图像,那么如果我更改亮度,我当前的代码将更改原始图像而不是裁剪后的图像的亮度. 同样,首先,如果我更改亮度,然后裁剪,则我的代码将裁剪原始图像,而不是变亮的图像.

My problem is with linking one function with another. if i crop image, then if i change brightness my current code changes brightness of original image rather than cropped image. similarly at first i if change brightness and then if i crop, my code will crop original image rather than brightened image.

下面的代码是更改亮度.

Below code is to change brightness.

function slider2_Callback(hObject, eventdata, handles)
fname = getappdata(0, 'fname');
[a, map] = imread(fname);
x = ind2rgb(a, map);
b = get(handles.slider2,'value');
j = imadjust(x,[],[],b);
    axes(handles.axes1);
    imshow(j);

下面的代码是裁剪

function crop_Callback(hObject, eventdata, handles)
fname = getappdata(0, 'fname');
[a, map] = imread(fname);
x = ind2rgb(a, map);
new = imcrop(x);
axes(handles.axes1);
imshow(new);

假设首先说如果我裁剪图像,然后再说下一步,如果以后更改裁剪图像的亮度,然后对上面编辑的图像进行其他操作,我该如何链接一个操作与另一个操作?

Suppose say at first if i crop image, then next step if i change brightness of cropped image later some other operation on above edited image, How can i link one operation with another?

推荐答案

您需要为图像提供一个全局变量,而不是为文件名添加全局变量.因此,在每个回调中,您都可以使用图像进行操作,而无需每次都读取图像.另外,您应在每次回叫结束时按setappdata保留所做的更改.因此,您的回调将如下所示:

Instead of having global variable for the file name, you need to have a global variable for the image. So in each of your callbacks you can manipulate with your image without reading the image every time. Also, you should keep your changes at the end of each call back by setappdata. Thus, your callbacks would be something like this:

function changeimage_Callback(hObject, eventdata, handles)
image = getappdata(0, 'image');

% manipulation on image
% show image

setappdata(0, 'image', image);

如果您有一个GUI,我认为如果您使用handles做这样的事情会更方便.也就是说,将图像加载到GUI中,并保持如下所示:

If you have one GUI, I think it would be more convenient if you do such a thing with handles. That is, load your image in your GUI and keep it like this:

handles.image = imread(filename);
guidata(hObject, handles);

然后您的回调将是这样的:

Then your callbacks would be like this:

function changeimage_Callback(hObject, eventdata, handles)

% manipulation on handles.image
% show handles.image

guidata(hObject, handles);

这篇关于在MATLAB中的同一GUI中更新数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆