function [allFiltered] = applyfilterfftsame(I, dogFilter);
% filter images by a bank of filters
% I: input images
% allFilter: filter bank
numImage = size(I, 2); % number of training images
h = (size(dogFilter, 1)-1)/2;  % half size of filters
[sx, sy] = size(I{1});  % size of images
allFiltered = cell(numImage, 1);  % filtered images
fftI = cell(numImage, 1); 

for (i = 1 : numImage)
   fftI{i} = fft2(I{i}, sx+h+h, sy+h+h);
end
fftf = fft2(dogFilter, sx+h+h, sy+h+h); 

for (i = 1 : numImage)
   fftIi = fftI{i}; 
   out = real(ifft2(fftIi.*fftf)); 
   filtered = out(h+1:h+sx, h+1:h+sy); 
   energy = filtered.*filtered;  % compute the local energy
   energy([1:h sx-h:sx],:) = 0.; energy(:,[1:h sy-h:sy]) = 0.; 
   ave = sum(sum(energy((h+1):(sx-h-1), (h+1):(sy-h-1))))/(sx-2*h-1)/(sy-2*h-1); 
   allFiltered{i} = energy/ave;  % normalizing by whitening
end
    
 
