How can I save all the amplitude and phase information of a FFT generated on ImageJ for sharing?

I would like to save on some sort of easily shareable format all the information included in an FFT of an image (say, a JPEG or PNG), such that the recipient can open it on ImageJ and recreate the original image doing an inverse FFT.

I have read online that a TIFF is a possible avenue to deal with this because it has different channels; however, I don’t know how to go about it, and I would appreciate very much an example.

Thank you!

How are you calculating the FFT or do you need a way to do so?

With the built-in FFT function in ImageJ.

The default “FFT” done by ImageJ is actually a Fast Hartley Transform:

This does not require multiple channels. As long as the format you pick is not lossy and can hold the image bit depth you need, then you should be fine. For example, if the resulting “FFT” is 8-bit a PNG might be just fine. JPG is not recommended.

Now if you want the Complex Fourier Transform, you need to enable this in options (Process > FFT > FFT Options). In this case, I get a 32-bit image. Now it seems the Complex Fourier Transform in ImageJ pads the image to the next power of 2 with the mean value, so you might get a padded version of the image on reversing the transform.

1 Like

How do you save both magnitude and phase?

1 Like

If you are actually using the Fast Hartley Transform, then there is no magnitude and phase. The result is completely real.

If you are using the Complex Fourier Transform, then you can save the real and imaginary components in a TIF file. You can calculate magnitude and phase from the real and imaginary components.

1 Like

Hi Toni

What is the goal of saving the FFT?? Why not just give the user a macro or script from which they can generate the FFT?? Just curious if it’s possible to just have the user start with the original image, and the script produces the FFT for them.


I understand how Fourier transforms are used to compress data by eliminating frequency components of an image, a segment in a piece of music or a video, but I presume the compressed data is transmitted also in Fourier space. It is this transmission part that I want to simulate.

1 Like

In that case you probably want to just dump the ‘coded’ data in a .raw file. Correct me if I am wrong, but it sounds like you are interested in writing your own compression scheme. I used to do a small amount of compression in a former life using Wavelets and Neural Networks.

Is your application something like the following???

  1. Perform Fourier Transform

At this point you will have the same amount of “information”. You may want to consider using imglib2 and/or ops to do the FFT, as it will return the real and complex parts of the FFT without redundant information (ie complex and real buffers, half the size +1, in the leading dimension).

  1. Coder

You will then have to apply a coder. Which could be lossless, or lossy, in this step you transform the FFT such that it can be stored with fewer bytes. (just writing the FFT won’t save any space, you have to transform it to a more compact form).

  1. At this point you could just write out the coded bytes and perhaps a header into a binary file. This is the file you transmit. By binary file, I mean you pack the header and transformed FFT into a byte array and dump it to a file.

on the recieving end you then need

  1. Decoder. This takes your coded FFT, and recreates the original FFT on the user side.

  2. Inverse FFT. This would recreate the original image.

So basicly you just want to dumb the raw bytes of your FFT (or transformed FFT) to a file, then read them at the recieving end. Does that makes sense?? Or have I completely misunderstood your application??


Thank you very much.

If I change the settings as you mentioned from FHT to complex, as in:

saving the output as a TIFF does indeed do the trick - I can later open up the TIFF, and do an inverse to get the initial image - more or less… The final image looks smaller. Also the FFT image doesn’t look like the typical spectral “nova explosion” typical of an image of a 2D FFT…

The idea is there, I am simply doing this to illustrate the principles behind compression and data transmission using Fourier. Your explanation is very comprehensive, and beyond my purpose at this point, although it points out the complexity of the actual process. Thank you!

Well, it did work a couple of examples, but now I am consistently getting this error message:

Or I get this:

as opposed to this:


The components are the real and imaginary components of the complex valued FT. If you want the magnitude, square both channels, add them up and take the square root.

I honestly do understand that part, and have played with extracting the values at some particular point, changing from polar to complex notation. I just don’t know why or how to save the FFT results as a TIFF without all the issues I have illustrated above (some weird wrap around with duplicated images of the original, error messages, etc) when I do the reverse FFT.

I am a bit confused about what changed between now and before? What did you do before the problem occurred?

I didn’t do anything differently. I got an image and did a FFT with the settings of the FFT as on the screen capture above - i.e. only Complex Fourier Transform selected. I saved as a TIFF. Then closed everything. I opened the saved FFT, and did an inverse FFT.


Now it seems to work again… With the image that used to create problems:

1 Like