簡體   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