# Convert a closed curve in an image to a parametric equation

I want to generate a parametric equation for a closed curve, which is defined in a 2d image (such as below). The equation is {x{t}, y{t}}; t is the length of the curve from an arbitrary starting point. I want to be able to give the equation to ParametricPlot an get the same closed curve.

A list of points {t, x(t), y(t)} are first extracted from the image in order. Then the data is used to form an InterpolatingFunction.

A single data point {t0, x(t0), y(t0)} seem to correspond to many pixels due to finite image resolution. How can I extract the desired points list?

• Would you be fine with B-splines? Nov 8 '17 at 14:01
• @J.M.I think it is ok. However, I am not familiar with B-splines. If the controlled points are sampled from the curve in the image, the generated B-spline curve will be inside the desired polygon. so it does not match the desired curve?
– cmc
Nov 9 '17 at 9:44
• In the B-spline case, you can derive the set of control points needed so that the resulting curve passes through the points determined from the original image. I'll work on this later, but you can try looking for my answers in the splines tag if you're impatient. Nov 9 '17 at 14:10

Look at this post: How to create a new "person curve"? ,maybe help.

We can use the function param and tocurve in Simon Woods's answer.

dat = ImageValuePositions[
SelectComponents[EdgeDetect@ColorNegate@Binarize@YOURPICTURE,
Large], 1];
ParametricPlot[
Evaluate[tocurve[#, 100, t] & /@ {Line[
dat[[Last[FindShortestTour[dat]]]]]}], {t, 0, 1}, Frame -> True,
Axes -> False]
tocurve[#, 100, t] & /@ {Line[dat[[Last[FindShortestTour[dat]]]]]}