mawus mawus - 1 year ago 89
Java Question

What should be the input and output for an FFT image transformation?

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:enter image description here

And this is what I've got:

enter image description here

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

Answer Source

You did not provide your source code ...

  1. 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)

  2. 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

  3. is your image resolution exact power of 2?

    if not zero pad it or the FFT would not work properly

  4. your example is wrong

    this is how it looks like in real:

    2D FFT example

    • 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:

    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:

power and wrap 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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download