# applyfilterfftsameLocalNorm

## PURPOSE

applyfilterfftsameLocalNorm - Filter image by a bank of filters with local normalization.

## SYNOPSIS

function allFiltered = applyfilterfftsameLocalNorm(I, allfilter)

## DESCRIPTION

     applyfilterfftsameLocalNorm - Filter image by a bank of filters with local normalization.

     I: input images
     allfilter: filter bank
     threshold: filter response is set to zero if below threshold

## CROSS-REFERENCE INFORMATION

This function calls:

This function is called by:

- GetNaturalStat GetNaturalStat - Obtain statistics from natural images.
- getGaborMaps getGaborMaps - Compute S1 maps from images whose paths are specified in .

## SOURCE CODE

    0001 function allFiltered = applyfilterfftsameLocalNorm(I, allfilter)
    0002 % applyfilterfftsameLocalNorm - Filter image by a bank of filters with local normalization.
    0003 %
    0004 % I: input images
    0005 % allfilter: filter bank
    0006 % threshold: filter response is set to zero if below threshold
    0007
    0008 numImage = size(I, 2);    % number of training images
    0009 numOrient = size(allfilter, 2);     % number of orientations
    0010 h = (size(allfilter{1}, 1)-1)/2;  % half size of filters
    0011 [sx, sy] = size(I{1});  % size of images
    0012 thresholdFactor = 0.01;
    0013
    0014 allFiltered = cell(numImage, numOrient);  % filtered images
    0015 for i = 1 : numImage
    0016     fftI{i} = fft2(I{i}, sx+h+h, sy+h+h);
    0017 end
    0018 for o = 1 : numOrient
    0019    fftf{o} = fft2(allfilter{1, o}, sx+h+h, sy+h+h);
    0020 end
    0021
    0022 radius = floor(h*2.5);
    0023 localHalfx = radius; localHalfy = radius;
    0024 for i = 1 : numImage
    0025    tot = 0.;
    0026    fftIi = fftI{i};
    0027    for (o = 1 : numOrient)
    0028       fftfo = fftf{o};
    0029       out = ifft2(fftIi.*fftfo);
    0030       filtered = out(h+1:h+sx, h+1:h+sy);
    0031       re = real(filtered); im = imag(filtered);
    0032       energy = re.*re + im.*im;  % compute the local energy
    0033       energy([1:h sx-h:sx],:) = 0.; energy(:,[1:h sy-h:sy]) = 0.;
    0034       allFiltered{i, o} = energy;
    0035       tot = tot + sum(sum(energy((h+1):(sx-h-1), (h+1):(sy-h-1))))/(sx-2*h-1)/(sy-2*h-1);
    0036    end
    0037    ave = tot/numOrient;
    0038    for o = 1 : numOrient
    0039        allFiltered{i, o} = allFiltered{i, o}/ave;  % normalizing by whitening
    0040    end
    0041        ClocalNormalizeDouble(sx, sy, numOrient, h, localHalfx, localHalfy, allFiltered(i, :), thresholdFactor);
    0042 end