簡體   English   中英

在 matlab 中的圖像上繪制點

[英]Plotting points over an image in matlab

我正在嘗試 plot p1, p2, p3在圖像上,我不確定如何有效地做到這一點,我可能遺漏了一些東西,這里是點的值: 在此處輸入圖像描述

這是我嘗試過的:

pts = load('myFile.mat')
p1 = pts.p1
p2 = pts.p2
p3 = pts.p3
im = imread ('myImg.JPG') % Loads the image compEx2 .JPG
imagesc (im) % Displays the image
plot(p1,p2, p3, 'r*', 'LineWidth', 2, 'MarkerSize', 2);
hold on

我遇到的第一個問題是,我不知道如何 plot 圖像中的所有 3 個變量p1,p2,p3 ,因為看起來它們已經在同一個變量中具有xy值,我該如何將其提取到plot呢?

此外,如果我嘗試以下操作,則不會在圖像中繪制點:

plot(p1,p2, 'r*', 'LineWidth', 2, 'MarkerSize', 2);

它只是繪制p1p2 也不確定如何將p3添加到 plot 中。 以及如何使其顯示在圖像上。

使用此代碼的 max 建議后:

imagesc (im) % Displays the image
colormap gray % changes the colormap of the current image to gray scale
hold on
plot([p1;p2;p3], 'r*', 'LineWidth', 4, 'MarkerSize', 4);

這些點繪制在圖像的邊緣:

在此處輸入圖像描述

將它們解包到坐標中:

x(1:3)=p1(:,1);
x(4:6)=p2(:,1);
x(7:9)=p3(:,1);

y(1:3)=p1(:,2);
y(4:6)=p2(:,2);
y(7:9)=p3(:,2);

然后

plot(x,y,...)

小心圖像坐標,也許這些點在xy坐標而不是圖像坐標中。

拆分xy坐標:

% merge vectors
P = [p1;p2;p3];
% split coordinates
x = P(:,1);
y = P(:,2);

% open figure with image
imshow(im);
% plot points
hold on
plot(x,y,'*')
hold off

如果您不將它們單獨提供給plot命令,它將假定它們是線(您只想將其 plot 標記)並將索引作為x軸的值

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM