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?
Try:
psd=abs(fftshift(fft2(Pc))).^2;
In dB:
psd=immultiply(log10(abs(fftshift(fft2(Pc)))), 20);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With