I need to take 2-d fft of an image. I dont hae any toolbox.
I want to use hamming or some other window function.
I can generate a 1-d vector coefficients of hamming window by using
the form for that. I know how to do it for 1-d fft.
But for 2-d matrix, how would one form the matrix which is the
product of original matrix and window function?
Suresh
% w - Window function, N x 1
% d - Image N x N
m = zeros(N,N); % Initialize space for mask
% Initialize windows along column direction
for n=1:N
m(:,n)=w;
end
% Apply windows along rows
m=m.*m';
% Compute windowed 2D DFT
D=fft2(d.*m);
HTH
Rune
"Suresh Narayanan" <sur...@aps.anl.gov> wrote in message news:<eeae1...@WebX.raydaftYaTP>...
If you go with Rune's method, it would be faster to use:
%---
m = w(:)*w(:).'; % Create 2D window
D = fft2(d.*m);
%---
This is called an outer product window, because it is created from a 1D window using the outer
product. One can also create a 2D window from a 1D window with what is called the rotational
method. In this method, you rotate the 1D window to create the 2D window (which involves
interpolation):
%---------
% Assume w symmetric so that rotation makes sense
% The image data is NxN.
%------
M = (N-1) / 2;
n = 2 / M * (-M:M);
[x,y] = meshgrid(n);
r = sqrt( x.^2 + y.^2 );
w_2D = zeros(N);
w_2D(:) = interp1(n, w, r(:));
w_2D(isnan(w_2D)) = 0;
%-----------
Almost any image processing book should cover this stuff. Here are two references which cover it
pretty well:
1) Two-Dimensional Signal and Image Processing, Jae S. Lim.
2) Multidimensional Digital Signal Processing, Dan Dudgeon and Russell Mersereau.
Hope that helped,
Jordan