Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am new to Mathematica, and using version 8.0.

I would like to calculate the 2D Fourier Transform of an Image with Mathematica and plot the magnitude and phase spectrum, as well as reconstruct the image with the inverse transform.

share|improve this question
Hello. You do not have to sign in post, you only need to update your profile data and we can see it on miniature. Also, it is good to show some research effort and minimal sample of data (image) you are working with. – Kuba Jul 26 '13 at 7:23
How about reading the documentation, like that on the Fourier function? – Sjoerd C. de Vries Jul 26 '13 at 8:52
Coming from another language its not clear at all that you need to convert your imagedata to (?image-)data (other than just loading it) before doing DFT. I got stuck for hours on this as well. The question and its answer are useful to me, thanks. – Leo Sep 26 '13 at 19:03
img = Import["ExampleData/lena.tif"];
Image[img, ImageSize -> 300]

Mathematica graphics

data = ImageData[img];(*get data*)
{nRow, nCol, nChannel} = Dimensions[data];
d = data[[All, All, 2]];
d = d*(-1)^Table[i + j, {i, nRow}, {j, nCol}];
fw = Fourier[d, FourierParameters -> {1, 1}];

(*adjust for better viewing as needed*)
fudgeFactor = 100;
abs = fudgeFactor*Log[1 + Abs@fw];
Labeled[Image[abs/Max[abs], ImageSize -> 300],Style["Magnitude spectrum", 18]]

Mathematica graphics

arg = Arg@fw;
Labeled[Image[arg/Max[arg], ImageSize -> 300],Style["Phase spectrum", 18]]

Mathematica graphics

ps. I do think Ms. Lena looks prettier in the spatial domain than in the frequency domain.

share|improve this answer
I think OP wants to reconstruct the image from spectrum. – Kuba Jul 26 '13 at 7:18
Thank You very much for the help.... Is there not a direct command of 2D DFT in MMA as 1D DFT in MMA???? – user8727 Jul 26 '13 at 10:28
Nice answer. Very basic question that requires knowledge of some differences between Mathematica and other languages. Im glad you gave him such a complete answer, it helped me too. And plus one for the PS! – Leo Sep 26 '13 at 19:05
I have post a question about your solution's extend.If you are available,help me please. – yode Mar 26 at 9:44

Mathematica also has a builtin function called ImagePeriodogram that returns an Image representing the power spectrum of the image. This won't help with phase spectra or reconstructing images, however.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.