ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkStandardDeviationProjectionImageFilter_h 00019 #define __itkStandardDeviationProjectionImageFilter_h 00020 00021 #include "itkProjectionImageFilter.h" 00022 #include "itkConceptChecking.h" 00023 00024 namespace itk 00025 { 00048 namespace Functor 00049 { 00050 template< class TInputPixel, class TAccumulate > 00051 class StandardDeviationAccumulator 00052 { 00053 public: 00054 typedef typename NumericTraits< TInputPixel >::RealType RealType; 00055 00056 StandardDeviationAccumulator( SizeValueType size ) 00057 { 00058 m_Size = size; 00059 m_Values.reserve(size); 00060 } 00061 00062 ~StandardDeviationAccumulator(){} 00063 00064 inline void Initialize() 00065 { 00066 m_Sum = NumericTraits< TAccumulate >::Zero; 00067 m_Values.clear(); 00068 } 00069 00070 inline void operator()(const TInputPixel & input) 00071 { 00072 m_Sum = m_Sum + input; 00073 m_Values.push_back(input); 00074 } 00075 00076 inline RealType GetValue() 00077 { 00078 // to avoid division by zero 00079 if ( m_Size <= 1 ) 00080 { 00081 return NumericTraits< RealType >::Zero; 00082 } 00083 00084 typename NumericTraits< TInputPixel >::RealType mean = 00085 ( (RealType)m_Sum ) / m_Size; 00086 typename std::vector< TInputPixel >::iterator it; 00087 RealType squaredSum = NumericTraits< RealType >::Zero; 00088 for ( it = m_Values.begin(); it != m_Values.end(); it++ ) 00089 { 00090 squaredSum += vnl_math_sqr(*it - mean); 00091 } 00092 return vcl_sqrt( squaredSum / ( m_Size - 1 ) ); 00093 } 00094 00095 TAccumulate m_Sum; 00096 SizeValueType m_Size; 00097 std::vector< TInputPixel > m_Values; 00098 }; 00099 } // end namespace Function 00100 00101 template< class TInputImage, 00102 class TOutputImage, 00103 class TAccumulate = typename 00104 NumericTraits< typename TOutputImage::PixelType > 00105 ::AccumulateType > 00106 class ITK_EXPORT StandardDeviationProjectionImageFilter: 00107 public 00108 ProjectionImageFilter< TInputImage, TOutputImage, 00109 Functor::StandardDeviationAccumulator< typename 00110 TInputImage::PixelType, TAccumulate > > 00111 { 00112 public: 00113 typedef StandardDeviationProjectionImageFilter Self; 00114 00115 typedef ProjectionImageFilter< TInputImage, TOutputImage, 00116 Functor::StandardDeviationAccumulator< typename 00117 TInputImage::PixelType, 00118 TAccumulate > > Superclass; 00119 00120 typedef TInputImage InputImageType; 00121 typedef typename InputImageType::PixelType InputPixelType; 00122 00123 typedef SmartPointer< Self > Pointer; 00124 typedef SmartPointer< const Self > ConstPointer; 00125 00127 itkTypeMacro(StandardDeviationProjectionImageFilter, ProjectionImageFilter); 00128 00130 itkNewMacro(Self); 00131 00132 #ifdef ITK_USE_CONCEPT_CHECKING 00133 00134 itkConceptMacro( InputPixelToOutputPixelTypeGreaterAdditiveOperatorCheck, 00135 ( Concept::AdditiveOperators< TAccumulate, 00136 InputPixelType, 00137 TAccumulate > ) ); 00138 itkConceptMacro( InputHasNumericTraitsCheck, 00139 ( Concept::HasNumericTraits< InputPixelType > ) ); 00141 00142 itkConceptMacro( AccumulateHasNumericTraitsCheck, 00143 ( Concept::HasNumericTraits< TAccumulate > ) ); 00144 00146 #endif 00147 protected: 00148 StandardDeviationProjectionImageFilter() {} 00149 virtual ~StandardDeviationProjectionImageFilter() {} 00150 private: 00151 //purposely not implemented 00152 StandardDeviationProjectionImageFilter(const Self &); 00154 00155 void operator=(const Self &); //purposely not implemented 00156 }; // end StandardDeviationProjectionImageFilter 00157 } //end namespace itk 00158 00159 #endif 00160