libGaussian.h

Go to the documentation of this file.
00001 #ifndef __LIBGAUSSIAN_H__
00002 #define __LIBGAUSSIAN_H__
00003 
00004 #include "Image.h"
00005 
00006 //============================================================================
00007 //============================================================================
00008 template<class PRECISION>
00009 inline typename PromotionOf<PRECISION, Real>::type Gaussian(const PRECISION& rWhere, const PRECISION& rMean, const PRECISION& rSigma)
00010 {
00011   static const Real grSqrt2Pi = 2.50662827;
00012 
00013   return exp(-1 * sqr((rWhere - rMean) / rSigma) / 2) / rSigma / grSqrt2Pi;
00014 }
00015 
00016 //============================================================================
00017 //============================================================================
00018 template <class PRECISION>
00019 inline PROMOTION(PRECISION,Real)
00020 Gaussian(
00021     const PRECISION& rWhere, const PRECISION& rMean, const PROMOTION(PRECISION,Real)& rSigma
00022 )
00023   {
00024   return Gaussian(
00025       PROMOTION(PRECISION,Real)(rWhere),
00026       PROMOTION(PRECISION,Real)(rMean),
00027       PROMOTION(PRECISION,Real)(rSigma)
00028   );
00029   }
00030 
00031 //============================================================================
00032 //============================================================================
00033 template<int DIMENSIONALITY>
00034 ImageOf<Real, DIMENSIONALITY>*
00035 GaussianCurve(const PointOf<DIMENSIONALITY, Real>& ptrSigma, const PointOf<
00036     DIMENSIONALITY, int>& ptSupport)
00037 {
00038   typedef PointOf<DIMENSIONALITY, int> POINT;
00039   typedef ImageOf<Real, DIMENSIONALITY> SRC_OUT;
00040 
00041   SRC_OUT* psrc = new SRC_OUT();
00042   psrc->Allocate(ptSupport);
00043 
00044   const POINT ptMean = ptSupport / 2;
00045 
00046   forpoint(POINT,pt,0,ptSupport)
00047     {
00048     SetPoint(*psrc,pt,Gaussian(pt,ptMean,ptrSigma).CVolume());
00049     }
00050   HandoffPointer(psrc);
00051   return psrc;
00052 }
00053 
00054 #endif //#ifdef __LIBGAUSSIAN_H__

Generated on 6 Apr 2011 for Slicer3 by  doxygen 1.6.1