# Recognizing Lines in Pixel Arrays

This topic is 3435 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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".

1. 1
2. 2
Rutin
17
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633735
• Total Posts
3013597
×