mawus - 11 months ago 43

Java Question

I try to obtain the spectrum of an grayscale image using FFT Cooley–Tukey algorithm in Java.

I don't know exactly how to form the input for the algorithm and what values from the output to use in order to form the spectrum image.

Currently my input is an array of complex numbers, with Re = value of the pixel in 8bit grayscale domain and Im = 0;

After running the algorithm I obtain another array of complex numbers with the real part having a lot of values out of [0,255] range and imaginary part 0.

I have tried to create an image from the real numbers array modulo 256.

This is how the spectrum should look:

And this is what I've got:

Obviously I'me doing something terrible wrong but I don't know what.

Answer

You did not provide your source code ...

**your result looks like resolution tree**used for recursive resolution/frequency information scaling and feature extraction not

**FFT**!!! So may be your recursion is wrong or you overlap data (to code in-place**FFT**is almost insanity) you should start with**1D**transform and then use that for**2D**and visually check every stage (also the inverse transform to match original data)**your FFT output should have non zero Imaginary part !!!**look here How to compute Discrete Fourier Transform and into all sub-links in that answer of mine

**is your image resolution exact power of 2?**if not zero pad it or the

**FFT**would not work properly**your example is wrong**this is how it looks like in real:

- left is input image (copied from your question)
- middle is real part
- right is imaginary part

you can combine them to power spectrum

`=sqrt(Re*Re+Im*Im)`

the**Re**and**Im**image is amplified to be seen else just few white dots in the corners would be visible. Here some more examples:your expected result looks like shifted by half of the image resolution (so the center of symmetry is in center of image instead of in corners)

**[Edit1] power and wrap**

have added power and wrap functions to mine app so here is the result:

first the power is computed so `intensity=sqrt(Re^2+Im^2)`

and then wrap is done by shifting image by half size right and down. What is overlapping that comes from the other side back so just swap all points in all lines `swap((x,y),(x+xs/2,y))`

and then the same for all columns `swap((x,y),(x,y+ys/2))`

. Now the result matches the one from OP the app is here

Source (Stackoverflow)