【问题标题】:Matlab: Superimposing a plot on an image in GUIDEMatlab:在 GUIDE 中的图像上叠加绘图
【发布时间】:2011-11-04 10:45:48
【问题描述】:

在使用 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 参数用于 plot()

任何帮助将不胜感激,在此先感谢您。

【问题讨论】:

    标签: image user-interface matlab matlab-guide


    【解决方案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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-20
      • 2018-10-16
      • 1970-01-01
      • 2012-12-14
      • 1970-01-01
      • 1970-01-01
      • 2011-09-15
      • 1970-01-01
      相关资源
      最近更新 更多