简体   繁体   中英

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

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?

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 . Not sure how to add p3 into the plot too. and how to make it show on the image.

After using max's suggestion w/ this code:

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.

Split the x and y coordinates:

% 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

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