ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkDigitizerFunctor.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 itkDigitizerFunctor_h
19#define itkDigitizerFunctor_h
20
21#include "itkNumericTraits.h"
22#include "itkMath.h"
23
24namespace itk
25{
26namespace Statistics
27{
28
29template <typename TInput1, typename TInput2 = TInput1, typename TOutput = TInput1>
31{
32public:
33 using PixelType = TInput2;
34 using MaskPixelType = TInput1;
35
37 : m_MaskValue(1)
38 // Halved so that m_Max - m_Min (computed in operator()) stays within the
39 // representable range: for PixelType == double, RealType is also double,
40 // so NonpositiveMin() and max() have no headroom left and their
41 // difference would overflow to +inf, silently mapping every pixel to
42 // bin 0.
43 , m_Min(NumericTraits<PixelType>::NonpositiveMin() / 2)
44 , m_Max(NumericTraits<PixelType>::max() / 2)
45 {}
46
47 Digitizer(unsigned int numberOfBinsPerAxis, MaskPixelType maskValue, PixelType min, PixelType max)
48 : m_NumberOfBinsPerAxis(numberOfBinsPerAxis)
49 , m_MaskValue(maskValue)
50 , m_Min(min)
51 , m_Max(max)
52 {}
53
54 ~Digitizer() = default;
55
56 bool
57 operator!=(const Digitizer & other) const
58 {
60 (m_Min != other.m_Min) || (m_Max != other.m_Max);
61 }
62
63 bool
64 operator==(const Digitizer & other) const
65 {
66 return !(*this != other);
67 }
68
69 TOutput
70 operator()(const MaskPixelType & maskPixel, const PixelType & inputPixel) const
71 {
72
73 if (maskPixel != m_MaskValue)
74 {
75 return -10;
76 }
77 else if (inputPixel < this->m_Min || inputPixel >= m_Max)
78 {
79 return -1;
80 }
81 else
82 {
83 return Math::Floor<TOutput>((inputPixel - m_Min) / ((m_Max - m_Min) / (float)m_NumberOfBinsPerAxis));
84 }
85 }
86
87 unsigned int m_NumberOfBinsPerAxis{ 256 };
88
90
93};
94
95} // namespace Statistics
96} // namespace itk
97
98#endif
Define additional traits for native types such as int or float.
bool operator!=(const Digitizer &other) const
NumericTraits< PixelType >::RealType m_Min
bool operator==(const Digitizer &other) const
TOutput operator()(const MaskPixelType &maskPixel, const PixelType &inputPixel) const
Digitizer(unsigned int numberOfBinsPerAxis, MaskPixelType maskValue, PixelType min, PixelType max)
NumericTraits< PixelType >::RealType m_Max
Floor(TInput x) template< TReturn
Round towards minus infinity.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....