Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Given a straight line that deviates from the horizontal by at most 15 degrees.

On this straight line there are bumps on top at random places on the line. The combined width of the bumps is at most 10% of the length of the straight line (but could be as little as 3 or 4 % of the length) and the height of the bumps is at most 5% of the length of the straight line. I can sample and get the x and y co-ordinates of the top of the line every 1% of the lines length.

I need a formula for how much the line deviates from the horizontal.

This is actually part of an Optical Character Recognition program, and I need this formula to write the software to align a page that was scanned not perfectly horizontally.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

You can do a linear regression. The slope that comes out of it will be close to the tangent of the angle. Routines are available in any numerical analysis book, many computer packages, and Excel. Section 15.2 of Numerical Recipes has a discussion.

Added: if the bumps are rare enough and most of the line is correct, you could just pick a dozen or so points, form all the pairs, and calculate the slope for each pair. Most of them should agree, and that is the slope. You can use the two-point form for the line.

It still won't be exact-real numbers cannot generally be represented exactly in a computer and there are errors in the measurement of the points, the square root and tangent functions, etc.

share|improve this answer
    
I need the exact slope. Is there a mathematical way to determine which points are "bumps" and eliminate them and then recalculate? –  Harry Spier May 8 '12 at 0:41
2  
@HarrySpier There is no exact slope of a bumpy line because it's not a line. However, if you take a large sample of points (the more, the better) from the bumpy line and perform linear regression on the sample, the "bumpiness" will be averaged out across the entire line, giving you a very good approximation of the intended line. –  Austin Mohr May 8 '12 at 1:14
    
On the other hand, from the looks of things OP will want to do orthogonal regression/total least squares instead of the conventional least squares, since it seems both horizontal and vertical coordinates are noisy... –  J. M. May 8 '12 at 1:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.