Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to show points on image in matlab?

Tags:

matlab

i have some pixel points lets say p1(1,1) and p2(1,10).......and so on

i want to display these points on image in any color. how to do this?

like image 794
chee Avatar asked Oct 01 '10 18:10

chee


People also ask

How do you add points in Matlab?

addpoints( an , x , y ) adds points defined by x and y to the animated line specified by an . Create an animated line with the animatedline function. To display the updates on the screen, use drawnow or drawnow limitrate . New points automatically connect to previous points.

How do I find the pixel coordinates of an image in Matlab?

You can also obtain pixel value information from a figure with imshow by using the impixelinfo function. To save the pixel location and value information displayed, right-click a pixel in the image and choose the Copy pixel info option. Image Viewer copies the x- and y-coordinates and the pixel value to the clipboard.


2 Answers

MATLAB plot documentation is pretty comprehensive.

LineSpec properties lists the syntax for different styles of lines, colors, and points.

If you want more options, see LineSeries Properties. You can specify properties such as Marker (style), MarkerEdgeColor, MarkerFaceColor, and MarkerSize.

You can also use RGB triplets to define color, if you want to deviate from rgbcmykw.

Examples:

Plot a single point (3,4) with an orange five-pointed star marker:

p=[3,4];
plot(p(1),p(2),'Marker','p','Color',[.88 .48 0],'MarkerSize',20)

Plot an array of points with green 'o' markers:

p=round(10*rand(2,10));
plot(p(1,:),p(2,:),'go')

EDIT: If you've got all your points stored as p1=[x1,y1], p2=[x2,y2], etc., try reorganizing them into a 2xN matrix first. Either re-generate the points, or if you've already got them as single pairs, use

p=[p1;p2;p3]'; %# the [;] notation vertically concatenates into Nx2, 
               %# and the ' transposes to a 2xN
plot(p(1,:),p(2,:),'go')

Or, if you have a ton of points stored as single pairs, say up to p1000 or so, you could use eval (cringe).

p=[]; %# initialize p
for n=1:nPoints %# if you've got 1000 points, nPairs should be 1000
eval(['p(:,n)=p',num2str(n)],''); %#executes p(:,n)=pn' for each nPoint
end
like image 177
Doresoom Avatar answered Oct 05 '22 23:10

Doresoom


You can just use plot:

plot(p1(1), p1(2), 'ko');  % Small circle point in black.
plot(p1(1), p1(2), 'r.');  % Small dot in red.
like image 34
Peter Avatar answered Oct 06 '22 00:10

Peter