Sign in to follow this  
Haytil

Recognizing Lines in Pixel Arrays

Recommended Posts

Hello, I have a relatively simple problem that I wonder if there is an already-existent solution for: I have an array of 2D integer coordinates, representing pixels. The array in total represents an approximation of a curve. So when rendering the curve, I draw a line between the first coordinate and the second coordinate, then a line between the second and the third coordinate, and so forth. Because of the way I develop these curves, many of the coordinates are redundant. For example, the first, second, and third set of coordinates may all lie on the same line - so drawing a line between the first and second and then between the second and third would result in no visual difference than if I had simply drawn a line between the first and third. Because my line-drawing renderer is very slow, every redundant line I can remove would end up in a substantial time-saving (especially since many of the lines connect neighboring pixels). Because this array represents a curve, I cannot simply draw a line between the first and the final coordinate. What I need is to be able to run through the array and remove all redundancies. I'm sure with a bit of effort I could code up something that would be satisfactory, and if I have to, that's not a problem. But it seems like this is an algorithm that's likely been developed before - I just don't know the name. If anyone can point me to an algorithm that does what I require (run through a list of coordinates to remove redundant lines), than I would greatly appreciate it. Thank you.

Share this post


Link to post
Share on other sites
Have you tried the naive algorithm of just looking at adjacent line segments and "collapsing" (i.e. remove the middle point) them if the dot product between them is close to 1/-1 (i.e. they are almost parallel)?

For more involved solutions, I suggest googling for "line simplification".

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this