Blur
& Binarize
One way is to Blur
and then Binarize
with threshold exactly 0.5
(no need to adjust!):
MorphologicalTransform[Binarize[Blur[FillingTransform[Closing[img, 1]], 5], 0.5], "Remove"]
(In some cases (but not in this case) applying Blur
twice can give better results:
MorphologicalTransform[
Binarize[Blur[Blur[FillingTransform[Closing[img, 1]], 3], 4], .5], "Remove"]
)
If further smoothing is needed, one can apply this method separately to each component of the image using one of the methods from this thread:
i = Closing[img, 1];
cm = ComponentMeasurements[{MorphologicalComponents[i], ColorNegate@i}, {"MaskedImage",
"BoundingBox"}];
smoothComponent[img_, n_] :=
ImagePad[MorphologicalTransform[
Binarize[Blur[ImagePad[FillingTransform[ColorNegate@img], n], n], 0.5], "Remove"], -n];
smoothAllComponents[cm_, n_] := Module[{newComps, iW, iH},
newComps = smoothComponent[#, n] & /@ cm[[;; , 2, 1]];
{iW, iH} = ImageDimensions@i;
Image[Total[
Table[SparseArray[
Band[1 + Round@{iH - #[[2, 2]], #[[1, 1]]} &@cm[[i, 2, 2]]] ->
ImageData[newComps[[i]]], {iH, iW}], {i, Length[cm]}]]]];
Table[s[cm, n], {n, 20}]
Dilation
& Thinning
cm = ComponentMeasurements[img, "Image"];
Table[ColorNegate@ImagePad[Thinning[Dilation[ImagePad[cm[[2, 2]], r], r]], -r], {r, 1,
4, .5}]
Applying to each of the components individually:
i = Closing[img, 1];
cm = ComponentMeasurements[{MorphologicalComponents[i], ColorNegate@i}, {"MaskedImage",
"BoundingBox"}];
smoothComponent[img_, r_] := ImagePad[Thinning[Dilation[ImagePad[img, r], r]], -r];
smoothAllComponents[cm_, n_] := Module[{newComps, iW, iH},
newComps = smoothComponent[#, n] & /@ cm[[;; , 2, 1]];
{iW, iH} = ImageDimensions@i;
Image[Total[
Table[SparseArray[
Band[1 + Round@{iH - #[[2, 2]], #[[1, 1]]} &@cm[[i, 2, 2]]] ->
ImageData[newComps[[i]]], {iH, iW}], {i, Length[cm]}]]]];
Table[s[cm, n], {n, 20}]
It is easy to check that the output is identical to the one obtained in the previous section.