1
$\begingroup$

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.

enter image description here

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.

$\endgroup$
3
  • 2
    $\begingroup$ Add some abs() is how one cooks, not how to code. Include your code $\endgroup$
    – user28715
    Dec 20, 2017 at 2:32
  • 2
    $\begingroup$ "I see no indication of phase being used anywhere here" -- There is no indication of anything being used anywhere. Post your code! $\endgroup$
    – MBaz
    Dec 20, 2017 at 2:51
  • 4
    $\begingroup$ 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. $\endgroup$ Dec 20, 2017 at 3:25

1 Answer 1

6
$\begingroup$

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:

%%
[x,map] = imread('http://www.cs.cmu.edu/~chuck/lennapg/lena_std.tif'); %import image
%%
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');

enter image description here

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.