Monday, 16 June 2008

Fourier Transform of a Cat

I took the Fourier Transform of a cat...

But it wasn't very useful, so I took the Fourier Discrete Cosine Transform (DCT) of one instead, and that wasn't much use either, but when I DCT'd back I got a ghost cat.

And now, by way of explanation, here's what I really mean...

I loaded a photograph of a tiger into Mathematica, pulled out the grey values of each pixel, then Fourier transformed the data. The Mathematica discrete Fourier transform produces (as you'd expect) complex results from real data, so it was pretty much useless for rasterising back to graphic format.

Fortunately, Mathematica provides a means to obtain real results from a Fourier Transform, by performing Discrete Cosine Transforms (or Discrete Sine Transforms, DST). Doing this allowed me to transform the data corresponding to greyscale pixel values for the tiger image into a Fourier transform of the tiger. The result was mostly black pixels; not hugely interesting. The original greyscale, and the Fourier DCT image are shown below.





In theory, no information is lost when something undergoes a Fourier Transform. This means that transforming again (i.e. performing a reverse transformation) should yield the original data. Since I had to do a DCT in order to get real pixel values, there was a very slight loss of information, and a second DCT revealed a ghost cat:



UPDATE (July 16, 2008):
I've uploaded the Mathematica notebook (with the output stripped to keep it small, you'll have to re-evaluate the cells, but I provided the original tiger.jpg in the ZIP file too!). It's available at http://www.physical-thought.com/files/fourier-cat.zip

UPDATE (April 19, 2009):
The Mathematica notebook linked above is no longer available online. If you really want the file, you'll have to e-mail me and ask. I'll leave it as an exercise for the reader to find my e-mail address.

8 comments:

  1. I guess this was inspired by this: http://xkcd.com/26/ ?

    ReplyDelete
  2. Don't forget that some loss of information will occur due to truncating the integral. i.e not between minus infinity and infinity.

    ReplyDelete
  3. Indeed, though I'm fairly sure the amount of information lost in the Discrete Cosine form of the transform is greater than that which would be lost doing a full complex Fourier transform... as, indeed, I found when performing a double FT returns almost the same image, but performing a double DCT produces the "ghost cat"!

    ReplyDelete
  4. I love it!
    Are you planning on posting your notebook?

    ReplyDelete
  5. Actually the notebook doesn't have a huge amount of extra stuff in it; just the commands used to perform the transforms.

    If blogger allowed uploads of the non-image variety, I would have attached it when I made the original post. I'll see what I can do about putting the notebook on alternative hosting. Watch this space!

    ReplyDelete
  6. Update
    I've posted the Mathematica notebook. The ZIP file is now linked in the original post.

    ReplyDelete
  7. I searched it on tineye.com and found this version: http://cricketpaw.deviantart.com/art/Water-Tiger-125179350

    I think i like the fourier-ghostcat more ;)

    ReplyDelete