Skip to main content
Tweeted twitter.com/StackMma/status/882337769497952262
edited tags
Link
Alexey Popkov
  • 62.5k
  • 7
  • 163
  • 405
Source Link
yode
  • 27.8k
  • 4
  • 69
  • 183

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["https://i.sstatic.net/9mJL2.png"],"Byte"]]]] BinaryImageQ[binImg] 

Mathematica graphics

True

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

Pruning[Thinning[binImg], 10] 

Mathematica graphics

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.