Taking the Fourier transform is easy and fun!
Let's strip away some of the complexities in order to look at what is going on. First, remove the color formfrom the image, since this just complicates things (you can always do ittake the same fortransform of each color channel separately).
img = ColorConvert[Import["ExampleData/lena.tif"], "Grayscale"];
Here are the magnitude and phase of the Fourier transform:
(abs = Abs[Fourier[ImageData[img]]]) // Image
(arg = Arg[Fourier[ImageData[img]]]) // Image
To invert these, use:
Chop[InverseFourier[(abs E^(I arg))]] // Image
which is the same as we started with. The Chop
is needed because spurious (almost zero) complex numbers remain after the Inverse).
Notice how clear and concise this is... it's just taking Fourier
of the image, taking the Abs and Arg to get the magnitude and phase images, and then reconstructing using InverseFourier
on Abs*Exp[I Arg]
.
This is a bit simpler than usual. For one thing, the zero frequency is in the upper left hand corner (instead of the center, where one usually plots it). You can move this to the center using RotateLeft
on the transformed image, or by multiplying in the spatial domain by +/-1^(i,j)+/-1^(i,j)
as in Nasser's answer. Of course, then, to reconstruct, you have to rotate back. This also uses the default FourierParameters
, which may or may not be exactly what you want.