2

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)
MJay
  • 987
  • 1
  • 13
  • 36

1 Answers1

2

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);
Shai
  • 111,146
  • 38
  • 238
  • 371
  • if I calculate reconstruction error, `I_error = I - I_recon;` there are values in the image. what are they? – MJay May 18 '17 at 08:37
  • @MJay verify that these values are very small. They are probably due to numerical issues. See e.g., [this thread](http://stackoverflow.com/q/686439/1714410). – Shai May 18 '17 at 08:39