# Applying phase shift to the FFT of a 2D image

62 views (last 30 days)
Aidan on 23 Feb 2014
I have an RGB image that I would like to animate by applying increasing amounts of phase shift to it. An example of what I am trying to achieve is shown here: Example mov (although note that this is two images superimposed with phase offset in opposite directions). An example of my code looks like this:
Stim = ind2rgb(X,map); % convert indexed image to RGB
NoFrames = 10; % Set number of animation frames
FrameShift = linspace(0,2*pi,NoFrames); % Set phase shift (0:2pi) for each frame
figure;
for f = 1:numel(FrameShift) % For each animation frame...
F = fft2(Stim); % Perform fast fourier transform on original image
mag = abs(F); % Get magnitude
phase = angle(F)+ FrameShift(f); % Apply phase shift
phase = wrapTo2Pi(phase); % Wrap phase values > 2pi
ShiftedImage = mag.*exp(j*phase); % Recombine magnitude and phase
PhaseStim = real(ifft2(ShiftedImage)); % Perform inverse fourier transform
%======= Normalize image to range 0:255
Range = max(max(max(PhaseStim))) - min(min(min(PhaseStim)));
PhaseStim = uint8(((PhaseStim - min(min(min(PhaseStim))))/Range)*255);
%======= Plot results
subplot(1,2,1);
imshow(fftshift(phase));
title(['FFT phase = ',num2str(FrameShift(f)/pi),' * pi']);
subplot(1,2,2);
imshow(PhaseStim);
title('Image');
drawnow;
end
The RGB image output looks correct when the phase offset is 0 or 2*pi (identical to the original image) and at pi (contrast inversion of the original image). However, at all phase offsets in between, the image appears not to change. I noticed that if I change the number of frames (NoFrames) to 5 then when phase offset is pi/2, the image output does change, but not in the way I expect.
Please can anybody suggest what I might be doing wrong?
Prasobhkumar P. P. on 23 Oct 2019
fft executes DFT, which is cyclic.