John - 6 months ago 45

Java Question

I have an image that I want to transform to the frequency domain using FFT, there seems to be a lack of libraries for this for Java but I have found two. One is JTransforms and the other was less well known and doesn't have a name.

With the less well known one the 2D could only have length vales of powers of two but had simple to use methods like

`FastFourierTransform.fastFT(real, imaginary, true);`

I believe the relevant class would be

`DoubleFFT_2D`

`doubleFFT.realForwardFull(real);`

`the input array must be of size rows*2*columns, with only the first rows*columns elements filled with real data`

Sorry about the lengthy and poor explanation, if any additional information is needed I would be happy to provide it.

JTransforms Library and Docs can be found here: https://sites.google.com/site/piotrwendykier/software/jtransforms

Answer

It's too bad the documentation for JTransforms isn't available online other than a zipped download. It's very complete and helpful, you should check it out!

To answer your question: `DoubleFFT_2D.realForwardFull(double[][] a)`

takes an array of real numbers (your pixels). However, the result of the FFT will have two output values for each input value - a the real and the imaginary part of each frequency bin. This is why your input array needs to be twice as big as the actual image array, with half of it empty / filled with zeroes.

Note that all the FFT functions use `a`

not only for input, but also for output - this means any image data in there will be lost, so it might be desirable to copy to a different / larger array anyway!

The easy and obvious fix for your scenario would be to use `DoubleFFT_2D.realForward(double[][] a)`

instead. This one will only calculate the positive spectrum, because the negative side will be symmetrical to it. This is because your input values are real.

Also, check out the `RealFFTUtils_2D`

class in JTransforms, which will make it a lot easier for you to retrieve your results from the array afterwards :)