00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkStandardDeviationProjectionImageFilter_h
00018 #define __itkStandardDeviationProjectionImageFilter_h
00019
00020 #include "itkProjectionImageFilter.h"
00021 #include "itkNumericTraits.h"
00022 #include "itkConceptChecking.h"
00023
00024 namespace itk {
00047 namespace Function {
00048 template <class TInputPixel, class TAccumulate>
00049 class StandardDeviationAccumulator
00050 {
00051 public:
00052 typedef typename NumericTraits<TInputPixel>::RealType RealType;
00053
00054 StandardDeviationAccumulator( unsigned long size )
00055 {
00056 m_Size = size;
00057 m_Values.reserve( size );
00058 }
00059 ~StandardDeviationAccumulator(){}
00060
00061 inline void Initialize()
00062 {
00063 m_Sum = NumericTraits< TAccumulate >::Zero;
00064 m_Values.clear();
00065 }
00066
00067 inline void operator()( const TInputPixel &input )
00068 {
00069 m_Sum = m_Sum + input;
00070 m_Values.push_back( input );
00071 }
00072
00073 inline RealType GetValue()
00074 {
00075
00076 if( m_Size <= 1 )
00077 return NumericTraits<RealType>::Zero;
00078
00079 typename NumericTraits<TInputPixel>::RealType mean =
00080 ((RealType) m_Sum) / m_Size;
00081 typename std::vector<TInputPixel>::iterator it;
00082 RealType squaredSum = NumericTraits<RealType>::Zero;
00083 for( it = m_Values.begin(); it != m_Values.end(); it++ )
00084 {
00085 squaredSum += vnl_math_sqr(*it - mean);
00086 }
00087 return vcl_sqrt( squaredSum / ( m_Size - 1) );
00088 }
00089
00090 TAccumulate m_Sum;
00091 unsigned long m_Size;
00092 std::vector<TInputPixel> m_Values;
00093 };
00094 }
00095
00096
00097 template <class TInputImage,
00098 class TOutputImage,
00099 class TAccumulate= ITK_TYPENAME
00100 NumericTraits< ITK_TYPENAME TOutputImage::PixelType >
00101 ::AccumulateType >
00102 class ITK_EXPORT StandardDeviationProjectionImageFilter :
00103 public
00104 ProjectionImageFilter<TInputImage, TOutputImage,
00105 Function::StandardDeviationAccumulator< ITK_TYPENAME
00106 TInputImage::PixelType, TAccumulate > >
00107 {
00108 public:
00109 typedef StandardDeviationProjectionImageFilter Self;
00110
00111 typedef ProjectionImageFilter<TInputImage, TOutputImage,
00112 Function::StandardDeviationAccumulator< typename
00113 TInputImage::PixelType, TAccumulate > > Superclass;
00114
00115 typedef TInputImage InputImageType;
00116 typedef typename InputImageType::PixelType InputPixelType;
00117
00118 typedef SmartPointer<Self> Pointer;
00119 typedef SmartPointer<const Self> ConstPointer;
00120
00122 itkTypeMacro(StandardDeviationProjectionImageFilter, ProjectionImageFilter);
00123
00125 itkNewMacro(Self);
00126
00127 #ifdef ITK_USE_CONCEPT_CHECKING
00128
00129 itkConceptMacro(InputPixelToOutputPixelTypeGreaterAdditiveOperatorCheck,
00130 (Concept::AdditiveOperators<TAccumulate,
00131 InputPixelType,
00132 TAccumulate>));
00133 itkConceptMacro(InputHasNumericTraitsCheck,
00134 (Concept::HasNumericTraits<InputPixelType>));
00136
00137 itkConceptMacro(AccumulateHasNumericTraitsCheck,
00138 (Concept::HasNumericTraits<TAccumulate>));
00139
00141 #endif
00142
00143
00144 protected:
00145 StandardDeviationProjectionImageFilter() {}
00146 virtual ~StandardDeviationProjectionImageFilter() {}
00147
00148 private:
00149
00150 StandardDeviationProjectionImageFilter(const Self&);
00151
00152 void operator=(const Self&);
00153
00154 };
00155
00156 }
00157
00158 #endif
00159