Home > SaliencyToolbox > gaussian.m

gaussian

PURPOSE ^

gaussian - returns a 1d Gaussian kernel.

SYNOPSIS ^

function kernel = gaussian(peak,sigma,maxhw,varargin)

DESCRIPTION ^

 gaussian - returns a 1d Gaussian kernel.

 kernel = gaussian(peak,sigma,maxhw)
    Returns a 1d Gaussian kernel with peak as the value
    at the maximum and sigma as the standard deviation (in pixels).
    The half width (hw) of the kernel is determined by where the
    Gaussian drops off to 1 % of the peak value, but
    is bounded by maxhw (set to 0 for no bounding). 
    The kernel will be of length: 2 * hw + 1.

 kernel = gaussian(peak,sigma,maxhw, treshPercent)
    Use threshPercent (in % of peak value) instead of 1 %
    to determine the half width.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % gaussian - returns a 1d Gaussian kernel.
0002 %
0003 % kernel = gaussian(peak,sigma,maxhw)
0004 %    Returns a 1d Gaussian kernel with peak as the value
0005 %    at the maximum and sigma as the standard deviation (in pixels).
0006 %    The half width (hw) of the kernel is determined by where the
0007 %    Gaussian drops off to 1 % of the peak value, but
0008 %    is bounded by maxhw (set to 0 for no bounding).
0009 %    The kernel will be of length: 2 * hw + 1.
0010 %
0011 % kernel = gaussian(peak,sigma,maxhw, treshPercent)
0012 %    Use threshPercent (in % of peak value) instead of 1 %
0013 %    to determine the half width.
0014 
0015 % This file is part of the SaliencyToolbox - Copyright (C) 2006-2013
0016 % by Dirk B. Walther and the California Institute of Technology.
0017 % See the enclosed LICENSE.TXT document for the license agreement.
0018 % More information about this project is available at:
0019 % http://www.saliencytoolbox.net
0020 
0021 function kernel = gaussian(peak,sigma,maxhw,varargin)
0022 
0023 if isempty(varargin)
0024   threshPercent = 1;
0025 else
0026   threshPercent = varargin{1};
0027 end
0028 
0029 hw = floor(sigma * sqrt(-2 * log(threshPercent / 100)));
0030 
0031 % cut the half width off if it is too large
0032 if ((maxhw > 0) & (hw > maxhw)) 
0033   hw = maxhw; 
0034 end
0035 
0036 % get the right peak value (if peak = 0, normalize area to 1)
0037 if (peak == 0) 
0038   peak = 1 / (sigma * sqrt(2*pi)); 
0039 end
0040 
0041 % build the kernel
0042 sig22 = -0.5 / (sigma * sigma);
0043 tmp = peak * exp(- [1:hw].^2 / (2*sigma*sigma));
0044 kernel = [tmp(hw:-1:1) peak tmp];

Generated on Thu 18-Jul-2013 06:10:46 by m2html © 2005