How to trace curvy lines in an image in Python?

990 Views Asked by At

I'm trying to trace a few curvy lines (vessels) in a retina image. The vessels are very clear in the image, so I thought this would be very straight forward, but I'm having a hard time figuring this out. Here is a link to the actual image: https://drive.google.com/open?id=1cRTk37U7LSeaV6rhvg0K6FKYsnDhlQZr

enter image description here

And I'm looking for the following tracing. Also would like to have that red tracing in a separate file:

enter image description here

1

There are 1 best solutions below

2
fmw42 On

Here is one possible approach implemented in Imagemagick. You likely can find similar functionality in OpenCV. Not the best detection, but gets most of the lines.

Filter noise (20 iterations of -enhance) -- median filtering should work.

Perform local area (adaptive) thresholding (-lat)

Perform morphology thinning

Use connected components processing to remove small isolate regions (<100)

Do morphology dilate to thicken the lines.


Input:

enter image description here

convert img.jpg \
-enhance -enhance -enhance -enhance -enhance \
-enhance -enhance -enhance -enhance -enhance \
-enhance -enhance -enhance -enhance -enhance \
-enhance -enhance -enhance -enhance -enhance \
-negate -lat 50x50+1% \
-morphology Thinning:-1 Skeleton \
-define connected-components:area-threshold=100 \
-define connected-components:mean-color=true \
-connected-components 4 \
-morphology dilate octagon:3 \
result.png


enter image description here