Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am new to Mathematica and using Version 8.0.

I want to calculate the 2D-Fourier Transform of a digital image and see its Magnitude and Phase Spectrum, and reconstruct it.

share|improve this question
3  
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

1 Answer 1

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
    
+1 (you forgot to reconstruct) –  Kuba Jul 26 '13 at 7:10
    
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

Your Answer

 
discard

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.