繁体   English   中英

创建图形时,MATLAB自动缩放到特定点

[英]MATLAB auto zoom to specific point when figure is created

我写了一些代码,它们将遵循附图中显示的黑色边缘。 每次选择下一个点时,都会重新绘制图形以显示更新。 这样做,所以我可以动画的方式演示代码。

在此输入图像描述

我想自动放大特定点(红色方块包围的中心青色点)。 希望是自动缩放区域将跟踪该点,因为它跟踪黑色边缘。

以下代码作为函数编写,每次检测到下一个边缘像素时,我都会在主脚本上调用它。

我已经尝试将轴的范围设置为围绕POI的范围,但是我无法使其工作。

function draw_point2(BinaryImage, P, P_r, P_c)
%P is a 1x2 array for the position of the current black pixel.
%P_r is nx1 list of all the row values for the detected pixels.
%P_c is nx1 list of all the column values for the detected pixels.


    cla
    r = P(1,1);
    c = P(1,2);
    figure (100)
    imshow(BinaryImage) , title('Binary image')
    hold on;
    plot(P_c, P_r, 'c.', 'LineWidth', 2); hold on
    %Current Black Pixel
    plot(c, r, 'c.', 'LineWidth', 2); hold on;

    % Possible Black Pixel - Next
    plot(c, r+1, 'rs', 'LineWidth', 2); hold on
    plot(c, r-1, 'rs', 'LineWidth', 2); hold on
    plot(c-1, r, 'rs', 'LineWidth', 2); hold on
    plot(c+1, r, 'rs', 'LineWidth', 2); hold on
    plot(c-1, r+1, 'rs', 'LineWidth', 2); hold on
    plot(c-1, r-1, 'rs', 'LineWidth', 2); hold on
    plot(c+1, r+1, 'rs', 'LineWidth', 2); hold on
    plot(c+1, r-1, 'rs', 'LineWidth', 2); hold on
    axis equal
    truesize;
end

谢谢


EDIT1

下图显示当前输出旁边的所需输出。 (它显示了我希望图形在绘制时的外观。它显示了POI的缩放(和中心)。在理想情况下,POI也总是以图形为中心 在此输入图像描述

使用功能axis

您可以使用axis([xmin xmax ymin ymax])定义限制。 在你的情况下, xmin将类似于c-20xmax=c+20

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM