# How to get a smooth ridge from a binary image

I always have this demand,but Mathematica cannot implement this perfectly for me.For example,I have such binary image

binImg = Uncompress[FromCharacterCode[
Flatten[ImageData[Import["http://i.stack.imgur.com/9mJL2.png"],"Byte"]]]]
BinaryImageQ[binImg]


True

I want to get a smooth ridge as far as possible.This is current method I can think out.

Pruning[Thinning[binImg], 10]


Of course,the SkeletonTransform can provide a little bit better result.But I have to say there is a long way to go.I mean I hope to get a result,the line more like a line,a rectangle more like a rectangle,a circle more like a circle in the result ridge image.In my case,I hope the result will more close to following red commponent.

• Maybe something like ImageAdjust[binImg~Blur~12~Erosion~6~RidgeFilter~1] – Simon Woods Jul 4 '17 at 10:11
• @SimonWoods Magic,man.. :) – yode Jul 4 '17 at 10:12
• @SimonWoods And you don't intend to post it as a answer?That will be a wonderful start I think. – yode Jul 4 '17 at 10:18
• I don't know Mathematica, but morphological processing (successive dilation and erosion) will go a long way. – Sanchises Jul 4 '17 at 17:47

ImageAdjust[binImg ~Blur~ 12 ~Erosion~ 6 ~RidgeFilter~ 1]

Thinning@SkeletonTransform@Binarize[Blur[binImg, 10], Method -> "Entropy"]