How to get spectrum of an image?
reference : Digital Image processing - Rafael Gonzalez

Steps :
The whole of filtering process can be summarized in the following points :
1> Given an input image f(x,y) of size M X N, obtain the padding parameters P and Q as P =2M and Q = 2N

The problem with using DFT is that both the input and output images are periodic. This causes interference between adjacent periods if the periods are close with respect to the duration of the non-zero parts of the functions. So we padd  the image by using a padding function P having zeros equal to twice the image length.

2> Form a padded image f’(x,y) of size P X Q by appending the necessary numbers of zeros to f(x,y).

3> Multiply f’(x,y) by (-1)^x+y to center its transform

4> Compute the DFT, F(u,v) of the image.

f = imread('pic.jpg');
figure(1);
imshow(f);
title('original image');

PQ = paddedsize(size(f));
[U,V] = dftuv(PQ(1),PQ(2));
 F = fftshift(fft2(f,PQ(1),PQ(2)));

 S =  abs(F);
 ag = angle(F);

[l,p] = size(S);
d = max(max(S));
c = min(min(S));

for l = 1:1:l
    for p = 1:1:p
        S1(l,p) = (S(l,p)-c)*(255/(d-c));
    end
end

figure(2);
subplot(2,2,1);
imshow(uint8(S1));
title('Magnitude response without log transform');

% since dc dominates the values of spectrume, the dynamic range of other intensities in displayed image is compression. to bring out those details we perform log transformation.

[m,n] = size(ag);
d = max(max(ag));
c = min(min(ag));

for l = 1:1:l  
    for p = 1:1:p
        ag1(l,p) = (ag(l,p)-c)*(255/(d-c));
    end
end

subplot(2,2,2);
imshow(uint8(ag1));
title('Phase response without log transform');