简体   繁体   English

在 matlab 中的图像上绘制点

[英]Plotting points over an image in matlab

I'm trying to plot p1, p2, p3 over an image, I'm not sure how to do that efficiently and I'm probably missing something, here are the values of the points:我正在尝试 plot p1, p2, p3在图像上,我不确定如何有效地做到这一点,我可能遗漏了一些东西,这里是点的值: 在此处输入图像描述

This is what I've tried:这是我尝试过的:

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

The first problem I have is, I'm not sure how to plot all the 3 variables p1,p2,p3 in the image, because it looks like they have x and y values already in the same variable, how do I extract it to plot it?我遇到的第一个问题是,我不知道如何 plot 图像中的所有 3 个变量p1,p2,p3 ,因为看起来它们已经在同一个变量中具有xy值,我该如何将其提取到plot呢?

Also, the points aren't plotted in the image if I try something like:此外,如果我尝试以下操作,则不会在图像中绘制点:

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

It just plots p1 and p2 .它只是绘制p1p2 Not sure how to add p3 into the plot too.也不确定如何将p3添加到 plot 中。 and how to make it show on the image.以及如何使其显示在图像上。

After using max's suggestion w/ this code:使用此代码的 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);

The points are plotted in the edge of the image:这些点绘制在图像的边缘:

在此处输入图像描述

Unpack them into coordinates:将它们解包到坐标中:

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);

then然后

plot(x,y,...)

Careful with image coordinates, maybe those points are in xy coordinates not image coordinates.小心图像坐标,也许这些点在xy坐标而不是图像坐标中。

Split the x and y coordinates:拆分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

If you don't provide them individually to the plot command, it will assume that they are lines (of which you only want to plot the markers) and take the index as the value for the x -axis如果您不将它们单独提供给plot命令,它将假定它们是线(您只想将其 plot 标记)并将索引作为x轴的值

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

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