ITK  4.3.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 {
48 namespace Functor
49 {
50 template< class TInputPixel, class TAccumulate >
52 {
53 public:
55 
57  {
58  m_Size = size;
59  m_Values.reserve(size);
60  }
61 
63 
64  inline void Initialize()
65  {
67  m_Values.clear();
68  }
69 
70  inline void operator()(const TInputPixel & input)
71  {
72  m_Sum = m_Sum + input;
73  m_Values.push_back(input);
74  }
75 
76  inline RealType GetValue()
77  {
78  // to avoid division by zero
79  if ( m_Size <= 1 )
80  {
82  }
83 
85  ( (RealType)m_Sum ) / m_Size;
86  typename std::vector< TInputPixel >::iterator it;
88  for ( it = m_Values.begin(); it != m_Values.end(); it++ )
89  {
90  squaredSum += vnl_math_sqr(*it - mean);
91  }
92  return vcl_sqrt( squaredSum / ( m_Size - 1 ) );
93  }
94 
95  TAccumulate m_Sum;
97  std::vector< TInputPixel > m_Values;
98 };
99 } // end namespace Function
100 
101 template< class TInputImage,
102  class TOutputImage,
103  class TAccumulate = typename
105  ::AccumulateType >
107  public
108  ProjectionImageFilter< TInputImage, TOutputImage,
109  Functor::StandardDeviationAccumulator< typename
110  TInputImage::PixelType, TAccumulate > >
111 {
112 public:
114 
115  typedef ProjectionImageFilter< TInputImage, TOutputImage,
117  TInputImage::PixelType,
118  TAccumulate > > Superclass;
119 
120  typedef TInputImage InputImageType;
121  typedef typename InputImageType::PixelType InputPixelType;
122 
125 
128 
130  itkNewMacro(Self);
131 
132 #ifdef ITK_USE_CONCEPT_CHECKING
133 
134  itkConceptMacro( InputPixelToOutputPixelTypeGreaterAdditiveOperatorCheck,
135  ( Concept::AdditiveOperators< TAccumulate,
137  TAccumulate > ) );
138  itkConceptMacro( InputHasNumericTraitsCheck,
141 
142  itkConceptMacro( AccumulateHasNumericTraitsCheck,
144 
146 #endif
147 
148 protected:
151 
152 private:
153  //purposely not implemented
155 
156  void operator=(const Self &); //purposely not implemented
157 }; // end StandardDeviationProjectionImageFilter
158 } //end namespace itk
159 
160 #endif
161