2
$\begingroup$

Starting with an image, I have taken its fourier transform and then modified it, and finally taken the inverse fourier transform of the modified fourier transform to get my resulting image. In my result, I get a lot of very small imaginary components in each pixel. My question is what causes these, and is there some insight into how I can play with a fourier transform in such a way that I won't get these imaginary components once I invert the transform at the end?

The reason this is an issue for me is because although I can simply zero out the imaginary components, or take the magnitude of each complex number as the pixel value and still obtain the resulting image that I desire, once I take the fourier transform of that new image, it does not yield the fourier transform that I used to generate the image previously. Because the English is getting messy, it's much easier to see in pseudocode:

function fft(input):
   return 2D fourier transform of input 2D array

function ifft(input):
   return 2D inverse fourier transform of input 2D array

function fix(image):
   zero out imaginary component in each pixel of input image (2D array)
   return updated image

// Suppose we have computed an input 2D matrix, and are ready to ifft it to get an image
input = /*...*/
test1 = fft(ifft(input))
test2 = fft(fix(ifft(input)))

While test1 will yield back the matrix (up to floating point errors) input that we started with, the image generated is not a real image. If we attempt to fix the image, we find that test2 significantly differs from our input.

What I would like to do is understand how to modify the fourier transform in such a way that I can achieve my original input after going through the process of taking the inverse fourier transform, storing that as a valid image, and then taking the fourier transform of that image.

$\endgroup$
3
  • 1
    $\begingroup$ You are seeing the effect of rounding errors. Try to compute the Fourier transform with better precision. $\endgroup$ Feb 26, 2018 at 18:15
  • 2
    $\begingroup$ If you want a transform which has strictly real output, you can use DCT instead of DFT. $\endgroup$ Feb 26, 2018 at 18:16
  • $\begingroup$ No, this is not the effect of rounding errors. If I take my input image, apply fft then ifft then clip off all imaginary components, then ifft, I get a result that is very close to the output of just applying fft to the original image. The fourier transform maps complex numbers to complex numbers, it's not an error if our output yields complex numbers. $\endgroup$ Feb 26, 2018 at 20:07

1 Answer 1

1
$\begingroup$

The Fourier Transform is the change of basis, the discrete signal from image, which is finite, gets transformed into sines. The transformation itself is prone to rounding, because in frequency domain there is no such thing as finite impulse or rectangular for that matter (see Gibbs effect), there will be some approximation.

The complex numbers represent the transformed signal, where amplitude is the length (magnitude) of the number while phase is the angle. Cutting off the imaginary part destroys the phase and changes the amplitude so image looks like a noise. There is no way to avoid Imaginary part (unless the image itself is fully even-symmetric then Im is zero).

The small components in Imaginary part cannot be avoided, extending precision will help a lot, but please keep in mind that some inputs cannot be preserved and some loss will occur. Using only magnitude and discarding the phase is equivalent to saving pixel intensities and discarding the location.

If you want to store FFT result as the valid image, the best idea is to produce two images, for Real and Imaginary part or another pair using Phase and Magnitude. Another idea is to save separate channels, which works for grayscale image but is not sn option for grayscale. This operation is very lossy, some fixed unsigned integer (for example 8bit) is converted into complex pair, both floating point, so using any standard storage option will lose crucial data. Probably to make it work the log transform would be need.

$\endgroup$
8
  • $\begingroup$ I don't think you've read the question carefully, please reread. Thanks for your effort though. $\endgroup$ Feb 27, 2018 at 20:00
  • $\begingroup$ My question: "What is the significance of the imaginary parts in the output of an Inverse Fourier Transform?" Your answer: talking about imaginary parts of the Fourier Transform. $\endgroup$ Feb 27, 2018 at 20:11
  • $\begingroup$ The significance of the question is: let test1 = fft(image); test2 = fft(real_part(ifft(test1))). If I now compare test1 and test2, they are very close (e.g. by using an L2 norm). If, on the other hand, I created test1 (e.g. by applying a filter in the fourier domain to the fft of an image), and then performed this same test as above, I will find that test2 is very far from test1 (and that the imaginary parts of the ifft of test1 are orders of magnitude larger than they were in the previous case). The goal is to understand how to avoid this. $\endgroup$ Feb 27, 2018 at 20:54
  • $\begingroup$ It's not a lucky test, it's just math. Anyway, I'll probably post in the Signal Processing site, this doesn't seem to be working. $\endgroup$ Feb 27, 2018 at 22:20
  • $\begingroup$ That's ridiculous, the fft of any image avoids it. You may not know how to avoid it; that does not make it unavoidable. $\endgroup$ Feb 28, 2018 at 1:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.