# measure angle between two lines, can rotation center constraint be used to refine the initial measured result?

I'm trying to measure the angle between two needle positions in an analog meter (gauge). such as:

After the image processing of several images, I get the processed image below(a image show different needle positions:

Here, the black dot points were the feature points of needle area, so I use the line fitting algorithm(usually by least square method, or Hough transform to find the line) to get several line positions. I can get the L1, L2, so the angle between those two lines was theta1. But the needle can located in many different places, so I can finally get many positions such as L3, L4...Ln. Those lines should be ideally intersect in one point, which is the rotation center of the needle. I can calculate the equivalent intersection point of all those lines (the red dot), since it is the rotation constraint of the movement.

So, my question is: How can the equivalent point be used to refine the final angle, I mean I want to get a better value of theta1, theta2, theta3....

Thanks.

You could recompute the lines with the constraint that they all go through the red point. If you normally optimize a line

$$y=ax+b$$

by optimizing both parameters $a$ and $b$, you would now only have 1 degree of freedom for each line. If the red point has coordinates $(x_1,y_1)$ then you get the constrained line equation

$$y=a(x-x_1)+y_1$$

with only one parameter $a$. Now you compute $a$ such that the squared distance to the other dots is minimized, and no matter which value of $a$ you obtain, the line will always pass through $(x_1,y_1)$.

• Hi, Matt L, thanks, this is a workable solution, I'm going test it to see whether it did improve the angle measurement. I first need to do some simulation. I put some random point around the idea line, and see whether your method improve the result. Apr 19 '14 at 14:24
• @ollydbg23 Don't you compute the red point simply by averaging all other intersection points? Apr 19 '14 at 14:29
• No, not average the individual intersection point, but I compute the red point by "total least square", that is to find a point which minimize the distant square sum to all the lines, is this OK? Apr 19 '14 at 14:43
• To find the equivalent point of several lines, I use an optimization method described in en.wikipedia.org/wiki/…. Apr 19 '14 at 15:04

Assume, you find the point of intersection as follows:

1. Let's say your optimum point is $(x,y)$. You could write the distance of this point from each line, for each line. That would read as: $\frac{a_ix+b_iy+c}{\sqrt{a_i^2+b_i^2}}$, where $a_i$, $b_i$, and $c_i$ are line coefficients. We could rewrite this as $a'_i=\frac{a_i}{\sqrt{a_i^2+b_i^2}}$, $b'_i=\frac{b_i}{\sqrt{a_i^2+b_i^2}}$ and $c'_i=\frac{c_i}{\sqrt{a_i^2+b_i^2}}$. Write the distance as $a'_ix+b'_iy+c'_i$. This is a linear equation and you have $N$ equations like that, where $N$ is the number of lines. You can set up an overdetermined linear system and solve for the optimum $a'_i$, $b'_i$ and $c'_i$. Then you could find back the original coefficients. Actually the optimal $(x,y)$ will lie on the nullspace of this matrix and can be obtained by SVD.

2. Let's now stick to: $\frac{a_ix+b_iy+c}{\sqrt{a_i^2+b_i^2}}$. What you could do is to use non-linear optimization (such as Gauss-Newton) to minimize the sum of these distance. You could also use this step to refine the previous one.

3. A more involved approach would include some fancy stuff: Intersecting those lines at a single point is actually called Triangulation. It could well be done by setting up a linear system of equations and solving for the optimum point. More detail: http://en.wikipedia.org/wiki/Triangulation_(computer_vision)

After finding the point of intersection you could either update rotation or the translation in order to enforce the line to pass through the optimum point.

• Hi, tbirdal, thanks for your help, I think the method you mentioned is much similar as I did. I follow the way as described in the wikipedia page: en.wikipedia.org/wiki/Line%E2%80%93line_intersection, especially in the section "n-line intersection". I'm not sure, but the wiki page does not involve the SVD. But when I fit the single line by "total least square" (see en.wikipedia.org/wiki/Total_least_squares )method, I did use SVD. Apr 19 '14 at 15:00