Search code examples
matlabimage-processingfftphasemagnitude

how to decompose an image into magnitude and phase and reconstruct it again using Matlab?


How can I decompose an image (e.g. Lena) into magnitude image and phase image and reconstruct it again from those two images using Matlab?

Here is the code I have written in Matlab but I dont know why the reconstructed image is too dark or too bright!

I = imread('lena.png');
I_fft = fft2(I);
I_amp = abs(I_fft);
I_phase = angle(I_fft);

I_fft_recon = I_amp .* exp(I_phase);
I_recon = ifft2(I_fft_recon);
imshow(I_recon)

Solution

  • You forgot to multiply the phase by the complex unit j:

    I_fft_recon = I_amp .* exp(j * I_phase);
    

    Everything else should be just fine.

    BTW, you might want to convert the image to double before processing

    I = im2double(I);