ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkStandardDeviationProjectionImageFilter.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
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 * https://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
24namespace itk
25{
46
47namespace Functor
48{
49template <typename TInputPixel, typename TAccumulate>
51{
52public:
54
56 {
57 m_Size = size;
58 m_Values.reserve(size);
59 }
60
62
63 inline void
65 {
66 m_Sum = TAccumulate{};
67 m_Values.clear();
68 }
69
70 inline void
71 operator()(const TInputPixel & input)
72 {
73 m_Sum = m_Sum + input;
74 m_Values.push_back(input);
75 }
76
77 inline RealType
79 {
80 // to avoid division by zero
81 if (m_Size <= 1)
82 {
83 return RealType{};
84 }
85
87 typename std::vector<TInputPixel>::iterator it;
88 RealType squaredSum{};
89 for (it = m_Values.begin(); it != m_Values.end(); ++it)
90 {
91 squaredSum += itk::Math::sqr(*it - mean);
92 }
93 return std::sqrt(squaredSum / (m_Size - 1));
94 }
95
96 TAccumulate m_Sum;
98 std::vector<TInputPixel> m_Values;
99};
100} // namespace Functor
101
102template <typename TInputImage,
103 typename TOutputImage,
106 : public ProjectionImageFilter<TInputImage,
107 TOutputImage,
108 Functor::StandardDeviationAccumulator<typename TInputImage::PixelType, TAccumulate>>
109{
110public:
111 ITK_DISALLOW_COPY_AND_MOVE(StandardDeviationProjectionImageFilter);
112
114
116 ProjectionImageFilter<TInputImage,
117 TOutputImage,
119
120 using InputImageType = TInputImage;
121 using InputPixelType = typename InputImageType::PixelType;
122
125
127 itkOverrideGetNameOfClassMacro(StandardDeviationProjectionImageFilter);
128
130 itkNewMacro(Self);
131
132 itkConceptMacro(InputPixelToOutputPixelTypeGreaterAdditiveOperatorCheck,
134 itkConceptMacro(InputHasNumericTraitsCheck, (Concept::HasNumericTraits<InputPixelType>));
135
136 itkConceptMacro(AccumulateHasNumericTraitsCheck, (Concept::HasNumericTraits<TAccumulate>));
137
138protected:
141}; // end StandardDeviationProjectionImageFilter
142} // end namespace itk
143
144#endif
typename NumericTraits< TInputPixel >::RealType RealType
Implements transparent reference counting.
~StandardDeviationProjectionImageFilter() override=default
ProjectionImageFilter< TInputImage, TOutputImage, Functor::StandardDeviationAccumulator< typename TInputImage::PixelType, TAccumulate > > Superclass
#define itkConceptMacro(name, concept)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType
Definition itkIntTypes.h:86