Monday, March 7, 2016

Drawing homer simpson with fourier transform

I was able to use the pixels directly as an imaginary number  x+i*y in the 3rd equation on wiki's discrete fourier transform article. This means in excel I had a table for the real part of each Xk that was x*cos(-2*pi*k*n/N)-y*sin(-2*pi*k*n/N) for each x pixel value as n pixels (rows) went from 0 to N and as k columns also varied from 0 to N, so it was a table with N rows and N colums. Then another table for the Xk imaginary part was y*cos()+x*sin(). Each column was summed for each table, so there was a real and imaginary part for each k, which is the goal, the fourier transform.  To generate the image back again from these imaginary numbers, the 4th equation on the wiki page is used.  So the R of each circle in the homer simpson epicycle video is each |Xk|/N. The rotation rate for each circle is 2*pi*k.  n/N is the "time", the fraction of the circle that has been completed.  k=0 gives the offset of the image away from the origin.  k=1 is the largest circle with the slowest rate.  The angle of Xk is an offset. 

The pixels do not have to need to be equal distance apart on the path of the line trace, and you may not even need to reverse course in collecting pixels on the line if an end-of-line is reached. Notice this occurs on the back hair in this video: the course was traced back on the hairs.  My version of excel can only do 243 points due to column limitations. It's a lot easier to program it than to use a spreadsheet. mobilefish site allowed me to extract xy coordinates from an uploaded image, but i could not get really them equal distance apart so my results were not very good. The more points you have, the more precision you have to have in making sure they are equal distance apart.  Also, you have to end 1 position next to pixel you began on.

Here's the video of drawing homer simpson as a sum of sinusoids

https://youtu.be/QVuU2YCwHjw

Here are my results on homer simpson and the batman symbol:



youtube comment giving details on how to do it:
This turned out very easy: Let the pixels equal an imaginary number  x+i*y in the 3rd equation on wiki's discrete fourier transform article. This gave me a table for the real part of each Xk that was x*cos(-2*pi*k*n/N)-y*sin(-2*pi*k*n/N) for each x pixel value as n pixels (rows) went from 0 to N and as k columns also varied from 0 to N, so it was a table with N rows and N colums. Then another table for the Xk imaginary part was y*cos()+x*sin(). Each column was summed for each table, so there was a real and imaginary part for each k, which is the goal, the fourier transform. To generate the image back from these imaginary numbers, the 4th equation on the wiki page is used (each circle in this video is from the 2nd equation and is 1/N*Xk*e^(i*z) = R*e^(i*(z+Wk)) where Xk=A+i*B=Rk*e^(i*Wk) from Euler's formula and z=2*pi*n*k/N). So the R of each circle is each |Xk|/N. You can reverse course in collecting pixels on the line if an end-of-line is reached and you're drawing a line between points. Notice this occurs on the back hair in this video. My version of excel can only do 243 points due to column limitations. It's a lot easier to program it than to use a spreadsheet, but I can't program the plotting. Mobilefish site allowed me to extract xy coordinates from an uploaded image .

No comments:

Post a Comment