ITK  4.13.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< typename TInputPixel, typename 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 += itk::Math::sqr(*it - mean);
90  }
91  return std::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< typename TInputImage,
101  typename TOutputImage,
102  typename 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  // Begin concept checking
133  itkConceptMacro( InputPixelToOutputPixelTypeGreaterAdditiveOperatorCheck,
134  ( Concept::AdditiveOperators< TAccumulate,
136  TAccumulate > ) );
137  itkConceptMacro( InputHasNumericTraitsCheck,
139 
140  itkConceptMacro( AccumulateHasNumericTraitsCheck,
142 
143  // End concept checking
144 #endif
145 
146 protected:
148  virtual ~StandardDeviationProjectionImageFilter() ITK_OVERRIDE {}
149 
150 private:
151  ITK_DISALLOW_COPY_AND_ASSIGN(StandardDeviationProjectionImageFilter);
152 
153 }; // end StandardDeviationProjectionImageFilter
154 } //end namespace itk
155 
156 #endif
ProjectionImageFilter< TInputImage, TOutputImage, Functor::StandardDeviationAccumulator< typename TInputImage::PixelType, TAccumulate > > Superclass
Base class for all process objects that output image data.
unsigned long SizeValueType
Definition: itkIntTypes.h:143
Implements an accumulation of an image along a selected direction.
bool sqr(const bool x)
Definition: itkMath.h:824
Define additional traits for native types such as int or float.
#define itkConceptMacro(name, concept)