It is not a pure segment question, normal segmentation algorithms are based on region, but this question has a prior rule, the line is smooth, So I think we can treat it as a route programming question.
we need some prework to make the goal line darker. it is thin, so we can use a dog filter to enhance it. (adjust dog filter’s two sigma, we can enhance object in specific scale)
force threshold the min value (suppress the too dark region)
dog filter to enhance the line
make a line roi from the start to the end, then find shortest route
we get a very perfect result:
the last question is how to find the start and end point. just for this image, there is a simple and safe method.
binarize the image, and do some morph repair.
get the boundary
find the start and end point
here we need a imagery point (not exist really, may be below the image’s center), then the start point is the nearest point in the left broundary, and the end point is the nearest point in the right broundary. It is easy to implemented with numpy.
idx = np.argmin(np.linalg.norm(left_broundary - imgpoint, axis=1))
the left_broundary[idx] is the start point. (the right is similar)