Reputation: 6498
I have an binary image containing the contours of some superpixels. I want to overlay this image on top of the original image but the contour lines are so thick that its hard to see what is inside the superpixels?
What would be a good way to narrow the contour lines of the superpixels down to a thickness of 1 pixel at maximum?
I tried to use opencv's erode
function with the standard 3x3 kernel but the result looked poorly (see image b) ). One cannot see the contours of the superpixels anymore. Has someone a better idea?
I was thinking of non-maximum suppression, but that only works if the pixels have more than two values such that a gradient can be computed ...
a) Raw image displaying contour lines of superpixels
b) Eroded image, contour lines are erased as well
Edit:
c) Image after thinning using Zhang-Suen's & Guo-Hall's algorithm
Upvotes: 0
Views: 3959
Reputation: 28954
Read something about morphological thinning or skeletonization.
For example: http://homepages.inf.ed.ac.uk/rbf/HIPR2/thin.htm
Erosion is a bit too "stupid" to deal with complex lines. It's better suited for cleaning up blob contours.
After the thinning operation you might want to use pruning to get rid of any unwanted segments.
They are standard tools in image processing. You should find plenty of resources online and in any decent text book.
Edited by Mark Setchell
Just to elucidate on Piglet's answer, the algorithm described in the referenced link is implemented in ImageMagick, so you can run it like this:
convert wireframe.png -morphology Erode Diamond -morphology Thinning:-1 Skeleton:2 result.png
And, if flickering images don't send your eyes mad, you can see the difference between the original wireframe and the skeletonised one here:
Upvotes: 2