ITK  4.4.0
Insight Segmentation and Registration Toolkit
itkStandardDeviationProjectionImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkStandardDeviationProjectionImageFilter_h
19 #define __itkStandardDeviationProjectionImageFilter_h
20 
22 #include "itkConceptChecking.h"
23 
24 namespace itk
25 {
47 namespace Functor
48 {
49 template< class TInputPixel, class TAccumulate >
51 {
52 public:
54 
56  {
57  m_Size = size;
58  m_Values.reserve(size);
59  }
60 
62 
63  inline void Initialize()
64  {
66  m_Values.clear();
67  }
68 
69  inline void operator()(const TInputPixel & input)
70  {
71  m_Sum = m_Sum + input;
72  m_Values.push_back(input);
73  }
74 
75  inline RealType GetValue()
76  {
77  // to avoid division by zero
78  if ( m_Size <= 1 )
79  {
81  }
82 
84  ( (RealType)m_Sum ) / m_Size;
85  typename std::vector< TInputPixel >::iterator it;
87  for ( it = m_Values.begin(); it != m_Values.end(); it++ )
88  {
89  squaredSum += vnl_math_sqr(*it - mean);
90  }
91  return vcl_sqrt( squaredSum / ( m_Size - 1 ) );
92  }
93 
94  TAccumulate m_Sum;
96  std::vector< TInputPixel > m_Values;
97 };
98 } // end namespace Function
99 
100 template< class TInputImage,
101  class TOutputImage,
102  class TAccumulate = typename
104  ::AccumulateType >
106  public
107  ProjectionImageFilter< TInputImage, TOutputImage,
108  Functor::StandardDeviationAccumulator< typename
109  TInputImage::PixelType, TAccumulate > >
110 {
111 public:
113 
114  typedef ProjectionImageFilter< TInputImage, TOutputImage,
116  TInputImage::PixelType,
117  TAccumulate > > Superclass;
118 
119  typedef TInputImage InputImageType;
120  typedef typename InputImageType::PixelType InputPixelType;
121 
124 
127 
129  itkNewMacro(Self);
130 
131 #ifdef ITK_USE_CONCEPT_CHECKING
132 
133  itkConceptMacro( InputPixelToOutputPixelTypeGreaterAdditiveOperatorCheck,
134  ( Concept::AdditiveOperators< TAccumulate,
136  TAccumulate > ) );
137  itkConceptMacro( InputHasNumericTraitsCheck,
140 
141  itkConceptMacro( AccumulateHasNumericTraitsCheck,
143 
145 #endif
146 
147 protected:
150 
151 private:
152  //purposely not implemented
154 
155  void operator=(const Self &); //purposely not implemented
156 }; // end StandardDeviationProjectionImageFilter
157 } //end namespace itk
158 
159 #endif
160