简体   繁体   中英

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.

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

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 在此输入图像描述

Use the function axis .

You can define the limits by using axis([xmin xmax ymin ymax]) . In your case xmin would be something like c-20 and xmax=c+20 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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