# applyfilterfftsameLocalNormMethod2

## PURPOSE

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

## SYNOPSIS

function [allfiltered] = applyfilterfftsameLocalNormMethod2(I, allfilter)

## DESCRIPTION

     applyfilterfftsameLocalNormMethod2 - 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:

- getGaborMapsMethod2 getGaborMapsMethod2 Compute S1 maps from images whose paths are specified in .

## SUBFUNCTIONS

- function v = sigmoidOnOriginalResponse(v)

## SOURCE CODE

    0001 function [allfiltered] = applyfilterfftsameLocalNormMethod2(I, allfilter)
    0002 % applyfilterfftsameLocalNormMethod2 - 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 nimage = size(I, 2);    % number of training images
    0009 norient = 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
    0013 allfiltered = cell(nimage, norient);  % filtered images
    0014 for i = 1 : nimage
    0015     fftI{i} = fft2(I{i}, sx+h+h, sy+h+h);
    0016 end
    0017 for o = 1 : norient
    0018    fftf{o} = fft2(allfilter{1, o}, sx+h+h, sy+h+h);
    0019 end
    0020
    0021 for i = 1 : nimage
    0022    fftIi = fftI{i};
    0023    for o = 1 : norient
    0024        fftfo = fftf{o};
    0025        out = ifft2(fftIi.*fftfo);
    0026        filtered = out(h+1:h+sx, h+1:h+sy);
    0027        re = real(filtered); im = imag(filtered);
    0028        energy = re.*re + im.*im;  % compute the local energy
    0029        allfiltered{i, o} = energy / mean(energy(:));
    0030    end
    0031 end
    0032
    0033 mask = ones(sx,sy);
    0034 mask([1:h sx-h:sx],:) = 0; mask(:,[1:h sy-h:sy]) = 0;
    0035
    0036 radius = floor(h*2.5);
    0037 aveFilter = ones(2*radius+1,2*radius+1)/((2*radius+1)^2);
    0038 for i = 1:nimage
    0039     localMeanMap = zeros(sx,sy);
    0040     for o = 1:norient
    0041         localMeanMap = localMeanMap + 1/norient * imfilter(allfiltered{i, o},aveFilter,'replicate');
    0042     end
    0043     for o = 1:norient
    0044         allfiltered{i,o} = allfiltered{i,o} ./ localMeanMap .* mask .* sigmoidOnOriginalResponse(allfiltered{i,o});
    0045     end
    0046 end
    0047
    0048 %% sigmoid transform
    0049 function v = sigmoidOnOriginalResponse(v)
    0050 v = 1 ./ ( 1 + exp( 1 * -( v - 3 ) ) );