Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compute power spectrum from 2D FFT

Tags:

matlab

fft

I've encounter a problem when doing my lab assignment, not sure how to implement this:

Use fft2 on a gray image and to do Fourier transform and then compute the power spectrum. This is my code so far:

>> Pc = imread('pckint.jpg');
>> whos Pc;
  Name        Size             Bytes  Class    Attributes

  Pc        256x256            65536  uint8              

>> imshow(Pc);
>> result = fft2(Pc);

My question is from the result. How to computer power spectrum?

like image 542
user1452954 Avatar asked Mar 22 '23 17:03

user1452954


2 Answers

Try:

psd=abs(fftshift(fft2(Pc))).^2;

In dB:

psd=immultiply(log10(abs(fftshift(fft2(Pc)))), 20);
like image 149
Cape Code Avatar answered Mar 27 '23 21:03

Cape Code


I guess that you are looking for the logarithmic form of FFT, because this is one of the better ways to express the power spectrum of the Fourier series, because the dynamic range of the spectrum is so large compared to the 8 bits of the display that the bright values in the center dominate the result, this difficulty is handled via a log transformation.

This is the way of doing in MATLAB:

I = imread('cameraman.tif');
imshow(I)
F = fft2(I);
shF = fftshift(F);
Log = log2(1 + abs(shF));
imshow(Log, []);

The empty brackets at the end of the imshow expression is necessary to display the image in the specifying range, for this case that means [min(I(:)) max(I(:))]; that is the minimum value in I is displayed as black, and the maximum value as white.

like image 35
monk Avatar answered Mar 27 '23 20:03

monk