-1

How can I convert set of points that (we can assume) create line made of segments (Top Image) to vector line (Bottom image)?

Is there some algorithm for that? Preferably C++ but even pseudocode will be ok.

enter image description here

zupazt3
  • 966
  • 9
  • 30
  • It think you're interested in edge detection techniques. – Gershom Maes Mar 24 '17 at 10:37
  • 1
    Am I? I think that edge detection will create contour (outline) and not a line. – zupazt3 Mar 24 '17 at 10:39
  • 1
    To clarify you have access to the exact set of points and their x,y positions? – CustodianSigma Mar 24 '17 at 11:11
  • Yes. This set of points created through flood fill algorithm. User choose color, tolerance, click on image and the program flood fills some region that is (presumably) a line, of which I want to have vertices. – zupazt3 Mar 24 '17 at 11:29
  • use thinning (morphology operators) then sample points and then apply connected components analysys. After that just distinguish lines and curves and fit/join/merge what you can. see [Approximate a curve with a limited number of line segments and arcs of circles](http://stackoverflow.com/a/42998651/2521214) – Spektre Mar 25 '17 at 06:31

1 Answers1

2

Here's how I would approach it:

  • Create contour/outline of raster image

  • Use these points as a vector contour/outline

  • Split the points in half so you have a line that describes the top edge and a line that describes the bottom edge of original outline

  • Take the bottom line (or top line) and use a line simplification algorithm (like Reumann-Witkam or Douglas-Peucker) to get a simplified vector line

  • Work out how much to offset the line by so it is roughly centered between the original two contour halves.

This should give you reasonable results without much computational complexity.

keith
  • 5,122
  • 3
  • 21
  • 50