简体   繁体   English

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

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

I have written some code that will follow the black edge shown in the attached image. 我写了一些代码,它们将遵循附图中显示的黑色边缘。 each time the next point is picked the figure is redrawn to show the update. 每次选择下一个点时,都会重新绘制图形以显示更新。 this is done so i can demonstrate the code in an animated way. 这样做,所以我可以动画的方式演示代码。

在此输入图像描述

i want to automatically zoom in on a specific point (the centre cyan point surrounded by red squares). 我想自动放大特定点(红色方块包围的中心青色点)。 the hope is that the auto zoomed area will follow the point as it traces the black edge. 希望是自动缩放区域将跟踪该点,因为它跟踪黑色边缘。

The following code is written as a function and i call it on my main script every time the next edge pixel is detected. 以下代码作为函数编写,每次检测到下一个边缘像素时,我都会在主脚本上调用它。

I have tried setting the range of the axis to be a range surrounding the POI however i couldn't get it working. 我已经尝试将轴的范围设置为围绕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

Thanks 谢谢


EDIT1 EDIT1

The following image shows the desired output next to the current one. 下图显示当前输出旁边的所需输出。 (it shows how i would like the figure to look when it is drawn. It shows the zoom (and centre) the POI. in an ideal case the POI would also always be centred in the figure (它显示了我希望图形在绘制时的外观。它显示了POI的缩放(和中心)。在理想情况下,POI也总是以图形为中心 在此输入图像描述

Use the function axis . 使用功能axis

You can define the limits by using axis([xmin xmax ymin ymax]) . 您可以使用axis([xmin xmax ymin ymax])定义限制。 In your case xmin would be something like c-20 and xmax=c+20 . 在你的情况下, xmin将类似于c-20xmax=c+20

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

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