Rendering PNG images to spline curves

I found something interesting on this page (Generic contour smoothing with shading) that could help me improve my images. Unfortunately, they can only be used with graphics generated by the software itself:

ClearAll[smoothCP]
smoothCP = Module[{pr = PlotRange @ #,
nF =  Nearest[Join @@ Cases[Normal @ #, Line[a_] :> Transpose[#2 /@ Transpose@a], ∞]]},
# /. GraphicsComplex[a_, b__] :> GraphicsComplex[
If[Or @@ MemberQ @@@ Thread @ {pr, #}, #, First @ nF @ #] & /@ a, b] ] &;
Row[{p1, smoothCP[p1, GaussianFilter[#, {25, 25}] &]}]


I tried to use a PNG image to improve the curves looking for a smooth spline or b-spline.

img = Import["https://i.stack.imgur.com/Yy0uN.png"]
Row[{img, smoothCP[img, GaussianFilter[#, {25, 25}] &]}]


I looked for something on the site, but I didn't find what I wanted.

Is it possible to obtain a smooth spline curve from PNG images?

Extracting a spline from the image is easiest with ImageMesh. I've used the midpoints of the lines on the mesh boundary for the BSplineCurve control points.

img = Import["https://i.stack.imgur.com/Yy0uN.png"];
mesh = ImageMesh@img;
midpoints = Midpoint /@ MeshPrimitives[mesh, 1];
Graphics[{Thick, Darker[Red],
BSplineCurve[midpoints, SplineClosed -> True]}]


You can also filter the curve to smooth it out, by replacing each point on the spline by the midpoint of its neighbours:

(* also try Partition[points, 3, 1] here too for a different effect *)
filter[points_] := Midpoint[#[[{1, 3}]]] & /@ Partition[points, 3, 2]
Manipulate[
Graphics[
BSplineCurve[Nest[filter, midpoints, k], SplineClosed -> True]]
, {k, 0, 7, 1}]


• I think I will have to create a Midpoint function, because I have version only Mathematica 11 software – LCarvalho Jun 15 at 0:03
• Midpoint[{x1_, y1_}, {x2_, y2_}] := {(x1 + x2)/2, (y1 + y2)/2} – LCarvalho Jun 15 at 0:29