makeGaborFilter - returns a 3d stack of 2d Gabor filters for each phase. filter = makeGaborFilter(gaborParams, angle, makeDisk) Returns a two-dimensional Gabor filter with the parameter: gaborParams - a struct with the following fields: filterPeriod - the period of the filter in pixels, elongation - the ratio of length versus width, filterSize - the size of the filter in pixels, stddev - the standard deviation of the Gaussian envelope in pixels. phases - the phase angles to be used. angle - the angle of orientation, in degrees, makeDisk - if 1, enforce a disk-shaped filter, i.e. set all values outside of a circle with diameter gaborParams.filterSize to 0. filter = makeGaborFilter(gaborParams, angle) Returns a two-dimensional Gabor filter, assuming makeDisk = 0. See also gaborFilterMap, defaultSaliencyParams.
0001 % makeGaborFilter - returns a 3d stack of 2d Gabor filters for each phase. 0002 % 0003 % filter = makeGaborFilter(gaborParams, angle, makeDisk) 0004 % Returns a two-dimensional Gabor filter with the parameter: 0005 % gaborParams - a struct with the following fields: 0006 % filterPeriod - the period of the filter in pixels, 0007 % elongation - the ratio of length versus width, 0008 % filterSize - the size of the filter in pixels, 0009 % stddev - the standard deviation of the Gaussian envelope in pixels. 0010 % phases - the phase angles to be used. 0011 % angle - the angle of orientation, in degrees, 0012 % makeDisk - if 1, enforce a disk-shaped filter, i.e. set all values 0013 % outside of a circle with diameter gaborParams.filterSize to 0. 0014 % 0015 % filter = makeGaborFilter(gaborParams, angle) 0016 % Returns a two-dimensional Gabor filter, assuming makeDisk = 0. 0017 % 0018 % See also gaborFilterMap, defaultSaliencyParams. 0019 0020 % This file is part of the SaliencyToolbox - Copyright (C) 2006-2008 0021 % by Dirk B. Walther and the California Institute of Technology. 0022 % See the enclosed LICENSE.TXT document for the license agreement. 0023 % More information about this project is available at: 0024 % http://www.saliencytoolbox.net 0025 0026 function filter = makeGaborFilter(gaborParams, angle, varargin) 0027 0028 if isempty(varargin) 0029 makeDisk = 0; 0030 else 0031 makeDisk = varargin{1}; 0032 end 0033 0034 % repare parameters 0035 major_stddev = gaborParams.stddev; 0036 minor_stddev = major_stddev * gaborParams.elongation; 0037 max_stddev = max(major_stddev,minor_stddev); 0038 0039 sz = gaborParams.filterSize; 0040 if (sz == -1) 0041 sz = ceil(max_stddev*sqrt(10)); 0042 else 0043 sz = floor(sz/2); 0044 end 0045 0046 rtDeg = pi / 180 * angle; 0047 0048 omega = 2 * pi / gaborParams.filterPeriod; 0049 co = cos(rtDeg); 0050 si = -sin(rtDeg); 0051 major_sigq = 2 * major_stddev^2; 0052 minor_sigq = 2 * minor_stddev^2; 0053 0054 % prepare grids for major and minor components 0055 vec = [-sz:sz]; 0056 vlen = length(vec); 0057 vco = vec*co; 0058 vsi = vec*si; 0059 0060 major = repmat(vco',1,vlen) + repmat(vsi,vlen,1); 0061 major2 = major.^2; 0062 minor = repmat(vsi',1,vlen) - repmat(vco,vlen,1); 0063 minor2 = minor.^2; 0064 0065 phase0 = exp(- major2 / major_sigq - minor2 / minor_sigq); 0066 0067 % create the actual filters 0068 for p = 1:length(gaborParams.phases) 0069 psi = pi / 180 * gaborParams.phases(p); 0070 result = cos(omega * major + psi) .* phase0; 0071 0072 % enforce disk shape? 0073 if (makeDisk) 0074 result((major2+minor2) > (gaborParams.filterSize/2)^2) = 0; 0075 end 0076 0077 % normalization 0078 result = result - mean(result(:)); 0079 filter(:,:,p) = result / sqrt(sum(result(:).^2)); 0080 end