I have an image :

img = imread('pic.jpg');

Now, How can I get spectrum of that 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');
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));

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));

title('Phase response without log transform');
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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