ITK  5.2.0
Insight Toolkit
itkOtsuMultipleThresholdsCalculator.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  * 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 itkOtsuMultipleThresholdsCalculator_h
19 #define itkOtsuMultipleThresholdsCalculator_h
20 
22 #include "itkHistogram.h"
23 
24 namespace itk
25 {
49 template <typename TInputHistogram>
50 class ITK_TEMPLATE_EXPORT OtsuMultipleThresholdsCalculator : public HistogramAlgorithmBase<TInputHistogram>
51 {
52 public:
58 
59  using MeasurementType = typename TInputHistogram::MeasurementType;
60  using FrequencyType = typename TInputHistogram::AbsoluteFrequencyType;
61 
65 
66  using MeanVectorType = std::vector<MeanType>;
67  using FrequencyVectorType = std::vector<FrequencyType>;
68  using WeightVectorType = std::vector<WeightType>;
69 
70  using InstanceIdentifierType = typename TInputHistogram::InstanceIdentifier;
71  using InstanceIdentifierVectorType = std::vector<InstanceIdentifierType>;
72 
74  itkTypeMacro(OtsuMultipleThresholdsCalculator, HistogramAlgorithmsBase);
75  itkNewMacro(Self);
77 
79  using OutputType = std::vector<MeasurementType>;
80 
82  const OutputType &
83  GetOutput();
84 
86  itkSetClampMacro(NumberOfThresholds, SizeValueType, 1, NumericTraits<SizeValueType>::max());
87  itkGetConstMacro(NumberOfThresholds, SizeValueType);
89 
91  void
92  Compute() override;
93 
95  itkSetMacro(ValleyEmphasis, bool);
96  itkGetConstReferenceMacro(ValleyEmphasis, bool);
97  itkBooleanMacro(ValleyEmphasis);
99 
102  itkSetMacro(ReturnBinMidpoint, bool);
103  itkGetConstReferenceMacro(ReturnBinMidpoint, bool);
104  itkBooleanMacro(ReturnBinMidpoint);
106 
107 
108 protected:
110  ~OtsuMultipleThresholdsCalculator() override = default;
111  void
112  PrintSelf(std::ostream & os, Indent indent) const override;
113 
115  bool
116  IncrementThresholds(InstanceIdentifierVectorType & thresholdIndexes,
117  MeanType globalMean,
118  MeanVectorType & classMean,
119  FrequencyVectorType & classFrequency);
120 
121 private:
122  SizeValueType m_NumberOfThresholds{ 1 };
124  bool m_ValleyEmphasis{ false };
125 #if defined(ITKV4_COMPATIBILITY)
126  bool m_ReturnBinMidpoint{ true };
127 #else
128  bool m_ReturnBinMidpoint{ false };
129 #endif
130 };
131 } // end of namespace itk
132 
133 #ifndef ITK_MANUAL_INSTANTIATION
134 # include "itkOtsuMultipleThresholdsCalculator.hxx"
135 #endif
136 
137 #endif
itk::OtsuMultipleThresholdsCalculator::m_Output
OutputType m_Output
Definition: itkOtsuMultipleThresholdsCalculator.h:123
itk::OtsuMultipleThresholdsCalculator< THistogram >::FrequencyType
typename THistogram ::AbsoluteFrequencyType FrequencyType
Definition: itkOtsuMultipleThresholdsCalculator.h:60
itk::OtsuMultipleThresholdsCalculator< THistogram >::VarianceType
typename NumericTraits< MeasurementType >::RealType VarianceType
Definition: itkOtsuMultipleThresholdsCalculator.h:63
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::OtsuMultipleThresholdsCalculator< THistogram >::OutputType
std::vector< MeasurementType > OutputType
Definition: itkOtsuMultipleThresholdsCalculator.h:79
itk::OtsuMultipleThresholdsCalculator< THistogram >::MeasurementType
typename THistogram ::MeasurementType MeasurementType
Definition: itkOtsuMultipleThresholdsCalculator.h:59
itk::OtsuMultipleThresholdsCalculator< THistogram >::WeightVectorType
std::vector< WeightType > WeightVectorType
Definition: itkOtsuMultipleThresholdsCalculator.h:68
itk::OtsuMultipleThresholdsCalculator< THistogram >::MeanType
typename NumericTraits< MeasurementType >::RealType MeanType
Definition: itkOtsuMultipleThresholdsCalculator.h:62
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itkHistogram.h
itkHistogramAlgorithmBase.h
itk::OtsuMultipleThresholdsCalculator< THistogram >::InstanceIdentifierVectorType
std::vector< InstanceIdentifierType > InstanceIdentifierVectorType
Definition: itkOtsuMultipleThresholdsCalculator.h:71
itk::OtsuMultipleThresholdsCalculator< THistogram >::FrequencyVectorType
std::vector< FrequencyType > FrequencyVectorType
Definition: itkOtsuMultipleThresholdsCalculator.h:67
itk::NumericTraits
Define additional traits for native types such as int or float.
Definition: itkNumericTraits.h:58
itk::OtsuMultipleThresholdsCalculator< THistogram >::MeanVectorType
std::vector< MeanType > MeanVectorType
Definition: itkOtsuMultipleThresholdsCalculator.h:66
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::OtsuMultipleThresholdsCalculator< THistogram >::InstanceIdentifierType
typename THistogram ::InstanceIdentifier InstanceIdentifierType
Definition: itkOtsuMultipleThresholdsCalculator.h:70
itk::NumericTraits::RealType
double RealType
Definition: itkNumericTraits.h:84
itk::OtsuMultipleThresholdsCalculator< THistogram >::WeightType
typename NumericTraits< MeasurementType >::RealType WeightType
Definition: itkOtsuMultipleThresholdsCalculator.h:64
itk::HistogramAlgorithmBase
base class for algorithms operating on histograms
Definition: itkHistogramAlgorithmBase.h:37
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83
itk::OtsuMultipleThresholdsCalculator
Computes Otsu's multiple thresholds for a histogram.
Definition: itkOtsuMultipleThresholdsCalculator.h:50