11

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.stack.imgur.com/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.

Alexey Popkov
  • 61,809
  • 7
  • 149
  • 368
yode
  • 26,686
  • 4
  • 62
  • 167

2 Answers2

19

You could try some kind of blurring or low-pass filter to smooth out some of the irregularity. For example

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

enter image description here

Simon Woods
  • 84,945
  • 8
  • 175
  • 324
5

Almost

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

Mathematica graphics

yode
  • 26,686
  • 4
  • 62
  • 167