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

binImg = Uncompress[FromCharacterCode[

Mathematica graphics


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.

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

2 Answers 2


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

  • $\begingroup$ I always think the upvote is a mysterious thing.Anyway,that include my one. :) $\endgroup$
    – yode
    Jul 6, 2017 at 11:16


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

Mathematica graphics


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.