MATLAB: Measurement angle of two drawn lines on Image.

angle measurementImage Processing Toolbox

I need to measure angle between two lines that I drawed. Actually I want to measure angles on face image for example eyes angle. I will draw two lines on image and I want to know angle between them. I'm creating gui that includes distance and angle measurement.
Is it possible that measure angles between drawn lines by me?

Best Answer

Do you detect the eye and draw the lines manually? If so, Let's forget the application and generalize the question as "measure the angle between two lines".
We will first figure out how to measure the angle of a line. When you draw the line, actually you defines its two endpoints. Let's say point 1 with location (x1,y1) and point 2 with location (x2,y2). The angle of this line in cartesian coordinate (your image) can be calculated by its tangent.
theta1 = atan((y1-y2)/(x1-x2));
The angle of second line can be calculated in the same way. Let's say line 2 has two points (x3,y3) and (x4,y4).
theta2 = atan((y3-y4)/(x3-x4));
Then, the angle between this two lines are the difference of theta1 and theta 2.
theta = theta1-theta2
Please remember the result is with unit radians. If you want degree, multiple the result by 180/pi.
Let me know, if I didn't make it clear.