I do have a binary image as shown below after applying various preprocessing and detection pipelines onto original image.
As seen in the picture there are actually 2 runways (tarmacs) for planes which are crossing each other on an intersection region. What I need is to split both runways and return their contours. I've checked opencv functions regarding contour features but had no luck. cv2.fitLine
seems ok but it only works if there is only a single line in the contour. Resulting image when the masks are applied should be looking like this:
Here's a possible approach, just done in Terminal with ImageMagick, but you should be able to do pretty much the same in Python with Wand or with scikit-image and the medial_axis.
First, skeletonise the image:
magick runways.png -threshold 50% -morphology Thinning:-1 Skeleton skeleton.png
Then run a "Hough Line Detection" looking for lines longer than 130 pixels and ask for the results in a tabular form:
magick skeleton.png -hough-lines 9x9+130 mvg:-
Output
# Hough line transform: 9x9+130
viewbox 0 0 464 589
# x1,y1 x2,y2 # count angle distance
line 297.15,0 286.869,589 # 255 1 476
line 0,591.173 464,333.973 # 189 61 563
That means it has detected 2 lines:
Just to illustrate, I'll draw the first in red and the second in green:
magick runways.png \
-fill red -draw "line 297,0 286,589" \
-fill lime -draw "line 0,591 464,333" result.png
Keywords: Python, image processing, skeleton, skeletonise, thinning, runway, runways, intersection, Hough Line Detection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With