Normal vector of line based on pixel coordinates

2 visualizzazioni (ultimi 30 giorni)
Philip
Philip il 28 Set 2011
I have an array that contains the x,y pixel coordinates of edges in an image. I want to use three of these coordinates at a time to work out the angle, and then obtain 5 or 10 pixel values that are located 90 degrees of this line.
For vertical and horizontal lines this is simple, as the pixel values corresponding to 90 degrees are either left/right or up/down in a straight line. For diagonal lines, I can just as easily take the diagonal values. However, how can I do this if the line is, say, 30 degrees or something more obtuse of 90 degrees?

Risposte (2)

Image Analyst
Image Analyst il 28 Set 2011
Use polyfit().
  2 Commenti
Philip
Philip il 28 Set 2011
Thanks! I've been reading the doc file, but I'm finding it difficult to know how I can apply it to my scenario. I will keep reading though! :)
Image Analyst
Image Analyst il 28 Set 2011
I've done this before. Basically get the coordinates along your curve that you want to fit a polynomial to then pass them plus the order of the polynomial (1 for a line) into polyfit. This will give you the slope and intercept. The slope of the perpendicular is -1/slope. Then use the point slope formula to get the slope of the new perpendicular line that goes through your point. Then use simple trig or algebra to get the endpoints of that line. Then you can use improfile to get equal spaced samples along that line (you specify the number of samples you want and improfile figures out what fractional pixel locations to extract them from). Hope that helps.

Accedi per commentare.


Walter Roberson
Walter Roberson il 29 Set 2011

Categorie

Scopri di più su Splines in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by