I would like to generate a parametric equation for a non-simple closed curve defined in a 2D image (shown below). This is the same problem as described in this question for simple curves.
However, when I use the solution given as an answer to this question, the resulting parametric look like the image below. I want the parametric to trace the lines, not to trace around the lines. How can I do this?
My current Mathematica code looks like this:
param[x_, m_, t_] := Module[{f, n = Length[x], nf},
f = Chop[Fourier[x]][[;; Ceiling[Length[x]/2]]];
nf = Length[f];
Total[Rationalize[
2 Abs[f]/Sqrt[n] Sin[Pi/2 - Arg[f] + 2. Pi Range[0, nf - 1] t], .01][[;; Min[m, nf]]]]]
tocurve[Line[data_], m_, t_] := param[#, m, t] & /@ Transpose[data]
dat = ImageValuePositions[
SelectComponents[EdgeDetect@ColorNegate@Binarize@IMAGE,
Large], 1];
ParametricPlot[
Evaluate[tocurve[#, 500, t] & /@ {Line[
dat[[Last[FindShortestTour[dat]]]]]}], {t, 0, 1}, Frame -> True,
Axes -> False]
tocurve[#, 500, t] & /@ {Line[dat[[Last[FindShortestTour[dat]]]]]}



SelectComponents[EdgeDetect@ColorNegate@Binarize@IMAGE, "Length", -1]and play with parameters. – Alex Trounev May 03 '21 at 17:25