how to convert an image into formulas

86 Views Asked by At

(That question is also posted in Stack Overflow, since I don't have enough reputation, you can see more detail images in the link above)

I was inspired by that, and wonder if I can do it in python. So I did what I thought would work:

  1. evaluate the edges of the image;
  2. take the image as a matrix, evaluate the position of the points, so I got a list like that, each corresponding $x$ and $y$ represents a point:

    $x:[62, 64, 73, 75, 62, 64 ...]$ $y:[146, 146, 146, 146, 145 ...]$

  3. now the points are not ordered, so I sorted them by distance, make them connected and from several lines;

  4. then I did Fast Fourier transform yo the x and y coordinates and receive this:

    $fftX:[ 92897.00000000+0.j, -16312.65365042-5708.43473681j, 6403.02886691-11902.98323505j ...]$

    $fftY:[ 108724.00000000+0.j, 1475.70696042-23102.57060654j, 9852.51853181+15423.22752527j ...]$

  5. I thought these complex numbers represents $C_n$ below:

    $s(x)=\sum_{n=-\infty}^{+\infty}C_ne^i$

    and I thought I can transform into the triangle form below:

    $A_nsin(\omega_nx+\varphi_n)$

  6. Also I believe that among them $A_n$ is $\sqrt{Re(C_n)^2+Im(C_n)^2}$; and $\varphi_n$ is $arg(C_n)$, so I constructed the formulas like that:

    $X(t): 185794.0+17282.618327763143\cdot sin(2t+-2.804972121911925)+13515.908721371954\cdot sin(4t+-1.0772633933209355)+11927.354784757847\cdot sin(6t+1.847507468889795)+...$

    $Y(t): 217448.0+23149.653985824472\cdot sin(2t+-1.5070066804712279)+18301.586508165863\cdot sin(4t+1.0023275010871453)+9432.725456145046\cdot sin(6t+-2.3755960165370666)+...$

But it's not, the output plot is a mass, looks totally different from the original image, more like a fractal pattern...

I'm not here to ask how to code, just want to know how to construct the formula like wolframAlpha did. Is my concept wrong? Or lack of some steps( like, in the eassy, the author make B-splines either)? Any way to make it correct? Or I should post that in Signal Processing Stack Exchange?