繁体   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