tags:

views:

82

answers:

2

I have two points lets say:

  • P(x,y) [point lies at the top of image]
  • P'(x',y') [point lies at bottom of image]

Now i want to draw a line betwen these two points....and the line should appear on image means should be visible.

how to do this????

+1  A: 

The simplest way to draw a line onto an image is to use PLOT.

%# read and display image
img = imread('autumn.tif');
figure,imshow(img)

%# make sure the image doesn't disappear if we plot something else
hold on

%# define points (in matrix coordinates)
p1 = [10,100];
p2 = [100,20];

%# plot the points.
%# Note that depending on the definition of the points,
%# you may have to swap x and y
plot([p1(2),p2(2)],[p1(1),p2(1)],'Color','r','LineWidth',2)

If you want a different color, either change the letter to any of rgbcmykw, or use RGB triplets (red is [1 0 0]). Have a look at the lineseries properties for more formatting options.

Jonas
and what if i want to find the slope of this line????
chee
@chee: The slope of the line is `(p2(2)-p1(2))/(p2(1)-p1(1))`. Also, if any answers to your questions are useful, please consider accepting (and upvoting) them. 0% acceptance rate is considered very bad form.
Jonas

related questions