MATLAB: Inverse Fourier transform error

ifft2MATLABrandom phase

Dear all, I have a question regarding inverser fourier transform.
I have the following code:
Test=imread('test.png');
FFT_Test=fft2(Test);
IFFT_Test=ifft2(FFT_Test);
Abs_FFT=abs(FFT_Test);
Angle_FFT=angle(FFT_Test);
Recon_FFT=Abs_FFT.*exp(i*Angle_FFT);
Result=ifft2(Recon_FFT);
I assume that "Result" and "IFFT_Test"/"Test" should be exactly the same, without imaginary part. However, it is not. The "abs(Result)" is the same as "IFFT_Test"/"Test", however, there appears some random phase in the "Result", which is really weird. On the left is my test image, and on the right is the random phase I get in the "Result". Can anybody help me?
Thanks a lot!

Best Answer

How are you doing the display of the images?
image(uint8(real(Result)))
looks fine to me for the images I tested with.
Result has some residual complex components, and will be of class double but with values nominally from 0 to 255 (but due to round-off you might get a slight negative value). Your original image is probably uint8(). The display routines treat double() color information differently than uint8() color, treating double() outside the range 0 to 1 as an error for 3D arrays (color images) and treating double() as 1-based indexing into the color map for 2D arrays (grayscale or two-level). uint8() 3D arrays are RGB Truecolor, and uint8() 2D arrays are 0-based indexing into the color map.
Related Question