# How does MATLAB recover picture from magnitude spectrum alone?

This is the transformation I did. The code fft2() the Lena picture than ifft2() it back to the original. Add some abs() so it actually displays it. According to this post an image cannot be reconstructed without the phase information, yet I see no indication of phase being used anywhere here.

I'm guessing MATLAB still uses it but keeps it out of sight for convinve. If so is it possible to view the phase component of a given picture as well as the magnitude spectrum?

CODE:

[x,map] = imread('PATH'); %import image
i = ind2gray(x,map);   % to greyscale

I = fft2(i); % 2D FFT

I = fftshift(I); % centre

ir = ifft2(I);

figure(1); imshow(abs(i),[]) % original
figure(2); imshow(log(double(abs(I))),[]) % original
figure(3); imshow(abs(ir),[]) % original


I guess I worded this really badly. How do I see the phase plot of the image's transform? I guess that sounds less stupid.

• Add some abs() is how one cooks, not how to code. Include your code – Stanley Pawlukiewicz Dec 20 '17 at 2:32
• "I see no indication of phase being used anywhere here" -- There is no indication of anything being used anywhere. Post your code! – MBaz Dec 20 '17 at 2:51
• The DFT is in general complex, even if the input image is purely real. If x is your image and you let y = fft2(x), then y will be complex valued. If you want to look at the phase, just use the angle function. – AnonSubmitter85 Dec 20 '17 at 3:25

Your code uses the phase for the reconstruction. Have a look at the output of fft2(x); they are complex numbers, i.e. the contain phase and magnitude. Have a look at this code:

%%
%%
i = rgb2gray(x);   % to greyscale

I = fft2(i); % 2D FFT

I = fftshift(I); % centre
mag = abs(I);
phase = angle(I);
I_magonly = abs(I);
I_phaseonly = I ./ abs(I);

figure(1);
subplot(321); imshow(abs(i),[]); title('Original');
subplot(322); imshow(log(double(abs(I))),[]); title('spectrum magnitude');
subplot(323); imshow(phase,[]); title('spectrum phase');
subplot(324); imshow(abs(ifft2(I)),[]); title('reconstructed');
subplot(325); imshow(abs(ifft2(I_magonly)),[]); title('reconstructed magnitude only');
subplot(326); imshow(abs(ifft2(I_phaseonly)),[]); title('reconstructed phase only'); It loads the Lena image, creates the FFT, and displays phase and magnitude information. Then it tries to reconstruct only based on phase or magnitude. Apparently, phase contains more information (for our eyes) than the magnitude. But you need to both exactly reproduce the image from its Fourier transform.