Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image Segmentation: Create polygons

I have input images which look like this:

enter image description here enter image description here

I like to segment the images in a way that i get approximated polygons which only contain horizontal an vertical lines.

My first approach was a hough segmentation, but i was only able to create rectangular objects. This does not work for the second image.

Then i tried to use a decision tree: For each image i trained a decision tree with the inputs x and y positions of all pixels and the classification black/white. Then i only used the first n layer of this tree. With this new tree i did a prediction for all pixels. Sometimes this worked well, but sometimes it didn't. Especially the tree depth varies from picture to picture...

Maybe someone has an idea how to do this? Or is there already an algorithm for this use case available?

Thank you very much

Regards

Kevin

like image 754
Kevin Meier Avatar asked Oct 12 '16 08:10

Kevin Meier


1 Answers

I get pretty reasonable results using a morphological "thinning" followed by an "erosion" to remove either horizontally or vertically oriented features. I am just doing it at the command-line with ImageMagick but you can use the Python bindings if you prefer.

So, horizontal features:

convert poly.png -threshold 50% -morphology Thinning:-1 Skeleton -morphology erode rectangle:3x1 im1h.png

enter image description here

And vertical features:

convert poly.png -threshold 50% -morphology Thinning:-1 Skeleton -morphology erode rectangle:1x3 im1v.png

enter image description here

And, using the other image:

convert poly2.png -threshold 50% -morphology Thinning:-1 Skeleton -morphology erode rectangle:1x3 result.png

enter image description here

like image 185
Mark Setchell Avatar answered Sep 30 '22 22:09

Mark Setchell