I have density plots for line locations. When visualizing the density plot image, multiple lines can be observed, each composed of one or more segments. I'm looking for a solution that would allow me to extract these lines and represent them as a list of points (e.g., [start_point, p2, p3, end_point]).
Is there an existing Python OpenCV (cv2) function or an open-source implementation that can help me achieve this? I would greatly appreciate any guidance or suggestions.
The density plot showing the line locations. (i.e.: what I have)
The line segments drawn with a line width of 1 pixel. (i.e.: what I want)
One approach I thought of is a brute-force method, where I would loop over all x's and then loop over all y's to detect the "humps" of each line segment and join them with nearby humps from the previous x. Then, I would merge segments that are near linear. I would repeat the process, looping over all y's and then x's, to detect vertical lines. However, I'm looking for a more efficient solution if possible.
Thank you in advance for your help!
fmw42 comment is the perfect solution.
Threshold. Then get contours. Then draw each one separately as white filled on black. Then thin using skimage skeletonize (scikit-image.org/docs/stable/auto_examples/edges/…) on the drawn contour. Then get the points along the skeleton for each contour. –