11

So I have this image 'I'. I take F = fft2(I) to get the 2D fourier transform. To reconstruct it, I could go ifft2(F).

The problem is, I need to reconstruct this image from only the a) magnitude, and b) phase components of F. How can I separate these two components of the fourier transform, and then reconstruct the image from each?

I tried the abs() and angle() functions to get magnitude and phase, but the phase one won't reconstruct properly.

Help?

Jordan
  • 3,998
  • 9
  • 45
  • 81
  • 1
    What do you mean by 'phase won't reconstruct'. You need both the magnitude and phase components for reconstruction. Leave any of them out and you won't get your image back. If you have only magnitude (r) and angle (x), you can do r(cos(x) + i sin(x)) to convert these into the form of a + bi, and use ifft2 on that. – Danyal Oct 18 '18 at 02:48

2 Answers2

11

You need one matrix with the same magnitude as F and 0 phase, and another with the same phase as F and uniform magnitude. As you noted abs gives you the magnitude. To get the uniform magnitude same phase matrix, you need to use angle to get the phase, and then separate the phase back into real and imaginary parts.

> F_Mag = abs(F); %# has same magnitude as F, 0 phase
> F_Phase = cos(angle(F)) + j*(sin(angle(F)); %# has magnitude 1, same phase as F
> I_Mag = ifft2(F_Mag);
> I_Phase = ifft2(F_Phase);
mtrw
  • 34,200
  • 7
  • 63
  • 71
  • I don't see this ffti() function you refer to, do you mean ifft2() perhaps? If not, do you have a link to the documentation for it? Also, I do not see this arg() function. – Jordan Oct 14 '11 at 06:24
  • Sorry, I was using Octave syntax for `arg` (equivalent to Matlab's `angle`) and made-up-in-my-head syntax for `ifft2`. – mtrw Oct 14 '11 at 06:37
  • 1
    where is the 'j' coming from? – Nathan Schwermann Sep 20 '12 at 03:09
  • 4
    @schwiz: `j = i = sqrt(-1)`. The history of this (apocryphally) is that `j` is used by engineers for the imaginary unit because `i` is already used for current. One might wonder why `c` is not used for current. Apparently, `i` denotes intensity, because early on electricity was analyzed in the context of fluid flow. By the time it was understood that complex number would be useful for analyzing electricity `i` was entrenched for current. – mtrw Sep 20 '12 at 06:21
  • @mtrw: `c` is for the speed of light. Great explanation on the use of `i`/`j` though :) – rayryeng Apr 22 '14 at 06:47
  • @rayryeng - Actually, according to http://en.wikipedia.org/wiki/Speed_of_light#Numerical_value.2C_notation.2C_and_units, Maxwell used `V` for the speed of light (Ampere had used `I` for current before http://en.wikipedia.org/wiki/Electric_current#Symbol). With `v` representing voltage and `V` being the unit, I guess we were doomed. – mtrw Apr 29 '14 at 13:35
  • Interesting... didn't know that. Thanks! – rayryeng Apr 29 '14 at 16:32
2

it's too late to put another answer to this post, but...anyway

@ zhilevan, you can use the codes I have written using mtrw's answer:

image = rgb2gray(imread('pillsetc.png')); 
subplot(131),imshow(image),title('original image');
set(gcf, 'Position', get(0, 'ScreenSize')); % maximize the figure window
%:::::::::::::::::::::
F = fft2(double(image));
F_Mag = abs(F); % has the same magnitude as image, 0 phase 
F_Phase = exp(1i*angle(F)); % has magnitude 1, same phase as image
% OR: F_Phase = cos(angle(F)) + 1i*(sin(angle(F)));
%:::::::::::::::::::::
% reconstruction
I_Mag = log(abs(ifft2(F_Mag*exp(i*0)))+1);
I_Phase = ifft2(F_Phase);
%:::::::::::::::::::::
% Calculate limits for plotting
% To display the images properly using imshow, the color range
% of the plot must the minimum and maximum values in the data.
I_Mag_min = min(min(abs(I_Mag)));
I_Mag_max = max(max(abs(I_Mag)));

I_Phase_min = min(min(abs(I_Phase)));
I_Phase_max = max(max(abs(I_Phase)));
%:::::::::::::::::::::
% Display reconstructed images
% because the magnitude and phase were switched, the image will be complex.
% This means that the magnitude of the image must be taken in order to
% produce a viewable 2-D image.
subplot(132),imshow(abs(I_Mag),[I_Mag_min I_Mag_max]), colormap gray 
title('reconstructed image only by Magnitude');
subplot(133),imshow(abs(I_Phase),[I_Phase_min I_Phase_max]), colormap gray 
title('reconstructed image only by Phase');
Leo
  • 75
  • 1
  • 11