
Notes:
One difficulty is that the molecules are not perfectly straight. So searching for straight lines doesn't work. The other difficulty is that the red segments can have very large gaps and that much (biochemical) noise is present in the image.
Since the green segments lie on the red segments I start from the middle of a green segment. A short line segment is put in this point it is turned around the point between a min and max angle. The direction with the highest average intensity is selected and the tracing continues there, if the average intensity is still higher in that direction than in the perpendicular direction. Otherwise the end has been found.
The molecules ends must have a certain distance from the images' borders and they must have a minimal length.