PROJECT 04-01 [Multiple Uses]
Two-Dimensional Fast FourierTransform
The purpose of this project is to develop a 2-D FFTprogram "package" that will be used in several other projects thatfollow. Your implementation must have the capabilities to:
(a) Multiply the input image by (-1)^x+y to center thetransform for filtering.
(b) Multiply the resulting (complex) array by a realfilter function (in the sense that the the real coefficients multiply both thereal and imaginary parts of the transforms). Recall that multiplication of twoimages is done on pairs of corresponding elements.
(c) Compute the inverse Fourier transform.
(d) Multiply the result by (-1)^x+y and take the realpart.
(e) Compute the spectrum.
Basically, this project implements the steps in Section4.7.3. If you are using MATLAB, thenyour Fourier transform program will not be limited to images whose size areinteger powers of 2. If you are implementing the program yourself, then the FFTroutine you are using may be limited to integer powers of 2. In this case, youmay need to zoom or shrink an image to the proper size by using the program youdeveloped in Project 02-04. See the Software section of the book web site tofind a 1-D FFT routine. Then use the method discussed in Sections 4.11.1 and4.11.2 for computing the 2-D FFT.
An approximation:To simplify this and the followingprojects (with the exception of Project 04-05), you may ignore image padding(Section 4.6.6). Although your resultswill not be strictly correct, significant simplifications will be gained notonly in image sizes, but also in the need for cropping the final result. Theprinciple swill not be affected by this approximation.
function g=TD_FFTs(f,H)
[M,N]=size(f);
P=2*M;Q=2*N;
%图像填充
fp=zeros(P,Q);
fp(1:M,1:N)=f(1:M,1:N);
%用(-1)^(x+y)乘以输入图像,来实现中心化变换
[Y,X]=meshgrid(1:Q,1:P);
ones=(-1).^(X+Y);
f=ones.*fp;
F=fft2(f);
%(-1)^(x+y)*f(x,y)的傅里叶变换等于fftshift(fft2(f,P,Q));
%以上可用F=fftshift(fft2(f,P,Q));
G=H.*F;%频率域相乘
g=real(ifft2(G));%反变换并取结果的实部
g=ones.*g;
g=g(1:M,1:N);%在g(x,y)左上象限提取M*N
end