Matlab:在GUIDE中叠加图像上的绘图

时间:2011-08-26 11:07:13

标签: image user-interface matlab matlab-guide

在使用Matlab的GUIDE时,我希望在图像上绘制一条线。当我在GUI中只使用一个轴时,我设法实现了这一点。但是,在添加另一个轴时,绘图不再覆盖图像。

最初情节开始在错误的轴上绘图,我意识到我忘了设置合适的轴。然而,一旦我选择了用于绘图的图像轴,要绘制的线不再位于图像的顶部,而只是用图形替换图像。

我的代码:

imshow(img(k),'Parent',handles.display)
hold on

x1 = line(k).point1(1);
y1 = line(k).point1(2);
x2 = line(k).point2(1);
y2 = line(k).point2(2);
plot(handles.display,[x1 x2],[y1 y2],'Color','r','LineWidth', 2)

hold off

添加新轴之前的代码与上面的代码相同,但handles.display的{​​{1}}参数。

非常感谢任何帮助,谢谢你。

1 个答案:

答案 0 :(得分:1)

调用HOLD函数时,还需要指定轴句柄。例如:

%# create some axes
hAx1 = subplot(121);
hAx2 = subplot(122);

%# draw in first: image with line overlayed
I = imread('coins.png');
imshow(I, 'Parent',hAx1)
hold(hAx1,'on')
plot(hAx1, [1 100], [1 100], 'Color','r', 'LineWidth',2)
hold(hAx1,'off')

%# draw in second
surf(hAx2, peaks)

enter image description here