ITK  5.0.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:
112  ITK_DISALLOW_COPY_AND_ASSIGN(StandardDeviationProjectionImageFilter);
113 
115 
116  using Superclass = ProjectionImageFilter< TInputImage, TOutputImage,
118  typename TInputImage::PixelType,
119  TAccumulate > >;
120 
121  using InputImageType = TInputImage;
122  using InputPixelType = typename InputImageType::PixelType;
123 
126 
129 
131  itkNewMacro(Self);
132 
133 #ifdef ITK_USE_CONCEPT_CHECKING
134  // Begin concept checking
135  itkConceptMacro( InputPixelToOutputPixelTypeGreaterAdditiveOperatorCheck,
136  ( Concept::AdditiveOperators< TAccumulate,
138  TAccumulate > ) );
139  itkConceptMacro( InputHasNumericTraitsCheck,
141 
142  itkConceptMacro( AccumulateHasNumericTraitsCheck,
144 
145  // End concept checking
146 #endif
147 
148 protected:
150  ~StandardDeviationProjectionImageFilter() override = default;
151 }; // end StandardDeviationProjectionImageFilter
152 } //end namespace itk
153 
154 #endif
Define numeric traits for std::vector.
unsigned long SizeValueType
Definition: itkIntTypes.h:83
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Base class for all process objects that output image data.
typename NumericTraits< TInputPixel >::RealType RealType
Implements an accumulation of an image along a selected direction.
~StandardDeviationProjectionImageFilter() override=default
#define itkConceptMacro(name, concept)