【发布时间】:2016-06-11 03:30:30
【问题描述】:
我需要创建一个显示图像的 GUI,并且用户必须能够执行以下操作:
1 - 使用鼠标选择多个点;
2 - 用户完成后,点击“返回”*;
3 - 点击“返回”后,如果用户想要编辑其中一个点,他/她必须单击所需的点并将其拖动到他/她想要的位置。
我创建了这个函数:
function [x, y] = test(img)
[lin, col] = size(img);
fig = figure('WindowButtonDownFcn', {@func, lin, col}, 'KeyPressFcn', @keyfunc);
imshow(img, []);
% axs = axes('position', [1 col 1 lin]);
set(gca, 'Ydir', 'reverse');
x = [];
y = [];
uiwait(fig);
function func(src, callback, lin, col)
seltype = get(fig, 'SelectionType');
set(gca, 'Ydir', 'reverse');
if strcmp(seltype, 'normal')
set(fig, 'Pointer', 'circle');
cp = get(fig, 'CurrentPoint');
xinit = cp(1, 1);
yinit = cp(1, 2);
x = [x, xinit];
y = [y, yinit];
hl = line('XData', xinit, 'YData', yinit, 'color', 'b', 'Marker', '.');
set(fig, 'WindowButtonMotionFcn', {@moveMouse, lin, col});
set(fig, 'WindowButtonUpFcn', @mouseRelease);
end
function moveMouse(src, callback, lin, col)
cp = get(fig, 'CurrentPoint');
xdata = [xinit, cp(1, 1)];
ydata = [yinit, cp(1, 2)];
set(hl, 'XData', xdata);
set(hl, 'YData', ydata);
drawnow;
end
function mouseRelease(src, callback)
last_selection = get(fig, 'SelectionType');
if strcmp(last_selection, 'alt')
set(fig, 'Pointer', 'arrow');
set(fig, 'WindowButtonMotionFcn','');
set(fig, 'WindowButtonUpFcn','');
else
return;
end
end
end
function keyfunc(src, callback)
keypressed = get(fig, 'CurrentCharacter');
if keypressed == 13
uiresume(fig);
end
end
end
Q1 - 它可以绘制图像,但坐标系在图形的左上角为零。 如何将它移到图片的左上角?
Q2 - 如何实现第 3 项(如果用户想要编辑其中一个点,他/她必须单击所需的点并将其拖动到他/她想要的位置)?
提前谢谢大家,
【问题讨论】:
标签: matlab matlab-figure matlab-guide