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.