1

That might be a question that is a little... big. I was inspired by that, and wonder if I can do it in python:

pic2for

Following its idea, I first got the edge of the image, take it as a matrix and evaluated the position of the points, then try to make it continuous, like that (apparently not beautiful... ): Demo

(If I don't do that, plot them by line willbe like this:)

OriPlot

Then I make fft to the x and y coordinates, got that:

[ 92897.00000000    +0.j         -16312.65365042 -5708.43473681j
   6403.02886691-11902.98323505j ...

I thought these number represents C_n below:

Demo_Formula

So I use these complex numbers, trying to construct an formula:

equ = ''
itera = 0
for comp in compList:  # compList is the list of the complex numbers
    mod = math.sqrt(comp.real**2 + comp.imag**2)
    arg = cmath.phase(comp)
    if not comp.imag == 0:
        equ += '+' + str(mod) + '*np.sin(' + str(itera*2) + '*t+' +\
            str(arg) + ')'
    else:
        equ += str(2 * comp.real)
    itera += 1

Which gave me this:

185794.0+17282.618327763143*np.sin(2*t+-2.804972121911925)+13515.908721371954*np.sin(4*t+-1.0772633933209355)+11927.354784757847*np.sin(6*t+1.847507468889795)+...

I do an eval() to it, thinking that'll be the formula, the total code is like this :

x, y = getBorder('target.png', maxRes = 256) 
x, y = sortNearest(x, y, maxDistance = 15) 

fx = np.fft.fft(x)
fy = np.fft.fft(y)

equaX = generateEqua(fx) #the codes beyond
equaY = generateEqua(fy)

t = np.linspace(0, len(x), 10000)
fsX = eval(equaX)
fsY = eval(equaY)

fig = plt.figure(figsize = (15, 15))
plt.plot(fsX, fsY, linewidth = 0.5)
plt.show()

And that's what it gave:Wrong Apparently not what I want...

Here I am not asking for details, just wonder where might be incorrect, is my concept wrong?Lack something? Or I use some wrong options?

Amarth Gûl
  • 1,040
  • 2
  • 14
  • 33
  • Have a look at this answer of mine: https://stackoverflow.com/a/44337719/1196549. The "skeletonization" step is irrelevant. You can also use a simpler fitting with line segments. –  Jun 09 '17 at 09:55

1 Answers1

0

If I am not totally wrong you should see, that if you scatterplot the image, that there are multiple y values for some x values. This would violate the basic principle of the Cartesian coordinate system. Therefore you cannot deduce a single formula for the image.

When working with images you usually use a 2D array of the coordinates and then apply functions to each x-y coordinate.

elhe
  • 122
  • 10
  • Indeed not possible for ordinary formula, from the eassy it seems the final formula is a parametric equation. – Amarth Gûl Jun 09 '17 at 05:15
  • Thanks for reminding me... I've forgot that Stack Exchange has more than one sub-sites. I'll have a try. – Amarth Gûl Jun 09 '17 at 05:21
  • I am very confident that you will be helped there. If you do post there, please post a link here for crossreference. – elhe Jun 09 '17 at 05:30
  • @AronC For future reference: This sort of question certainly does not belong on MathOverflow. However, it's entirely appropriate to ask on MathStackExchange. – Stefan Mesken Jun 09 '17 at 10:29
  • Ok, I am sorry for the confusion. I just read [this](https://math.meta.stackexchange.com/questions/41/differences-between-mathoverflow-and-math-stackexchange) meta post, and you are absolutly right. – elhe Jun 09 '17 at 14:25