ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkOtsuMultipleThresholdsCalculator.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 itkOtsuMultipleThresholdsCalculator_h
19 #define itkOtsuMultipleThresholdsCalculator_h
20 
22 #include "itkHistogram.h"
23 
24 namespace itk
25 {
48 template< typename TInputHistogram >
49 class ITK_TEMPLATE_EXPORT OtsuMultipleThresholdsCalculator:
50  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 & GetOutput();
83 
85  itkSetClampMacro( NumberOfThresholds, SizeValueType, 1, NumericTraits< SizeValueType >::max() );
86  itkGetConstMacro(NumberOfThresholds, SizeValueType);
88 
90  void Compute() override;
91 
93  itkSetMacro(ValleyEmphasis, bool);
94  itkGetConstReferenceMacro(ValleyEmphasis, bool);
95  itkBooleanMacro(ValleyEmphasis);
97 
100  itkSetMacro(ReturnBinMidpoint, bool);
101  itkGetConstReferenceMacro(ReturnBinMidpoint, bool);
102  itkBooleanMacro(ReturnBinMidpoint);
104 
105 
106 protected:
108  ~OtsuMultipleThresholdsCalculator() override = default;
109  void PrintSelf(std::ostream & os, Indent indent) const override;
110 
112  bool IncrementThresholds(InstanceIdentifierVectorType & thresholdIds,
113  MeanType totalMean,
114  MeanVectorType & classMean,
115  FrequencyVectorType & classFrequency);
116 
117 private:
118 
119  SizeValueType m_NumberOfThresholds{ 1 };
121  bool m_ValleyEmphasis{ false };
122 #if defined(ITKV4_COMPATIBILITY)
123  bool m_ReturnBinMidpoint{ true };
124 #else
125  bool m_ReturnBinMidpoint{ false };
126 #endif
127 };
128 } // end of namespace itk
129 
130 #ifndef ITK_MANUAL_INSTANTIATION
131 #include "itkOtsuMultipleThresholdsCalculator.hxx"
132 #endif
133 
134 #endif
Light weight base class for most itk classes.
Define numeric traits for std::vector.
unsigned long SizeValueType
Definition: itkIntTypes.h:83
Computes Otsu&#39;s multiple thresholds for a histogram.
base class for algorithms operating on histograms
typename NumericTraits< MeasurementType >::RealType MeanType
typename NumericTraits< MeasurementType >::RealType WeightType
typename NumericTraits< MeasurementType >::RealType VarianceType
Control indentation during Print() invocation.
Definition: itkIndent.h:49