Shifting in DFT (FFT) Input image



Listing-1

i = imread('Untitled.png');
i = rgb2gray(i);
F = fft2(i);
%%%F = fftshift(F);
F = abs(F);
F = log(F+1); 
F = mat2gray(F); 
imshow(F);


Output



.

Listing-2

i = imread('Untitled.png');
i = rgb2gray(i);
F = fft2(i);
F = fftshift(F);
F = abs(F);
F = log(F+1); 
F = mat2gray(F); 
imshow(F);


Output



Seeing the the above two outputs, can you answer the following questions,


Why does the FFT of an image produce such an spectrum where zero frequencies are at the corner of the image?
Why is that a problem (or, is that)?
Why does the shifting operation fixes that phenomenon?
It is all about defining the support of the DFT.
The DFT is periodic with period of $ 2 \pi $.
Hence on any support of the length $ 2 \pi $ you see all the data.

On default, when using MATLAB's fft() the result is on the range $ \left[ 0, 2 \pi \right] $, namely the Low Frequencies are at the beginning of the output vector.
Using fftshift() the DFT is shifted to match $ \left[ -\pi, \pi \right] $ support which means the DC Frequency is centered.

The same logic works on 2D DFT.