ITK  5.4.0
Insight Toolkit
itkOtsuThresholdImageFilter.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
19#ifndef itkOtsuThresholdImageFilter_h
20#define itkOtsuThresholdImageFilter_h
21
24
25namespace itk
26{
27
54template <typename TInputImage, typename TOutputImage, typename TMaskImage = TOutputImage>
55class ITK_TEMPLATE_EXPORT OtsuThresholdImageFilter
56 : public HistogramThresholdImageFilter<TInputImage, TOutputImage, TMaskImage>
57{
58public:
59 ITK_DISALLOW_COPY_AND_MOVE(OtsuThresholdImageFilter);
60
66
68 itkNewMacro(Self);
69
71 itkOverrideGetNameOfClassMacro(OtsuThresholdImageFilter);
72
73 using InputImageType = TInputImage;
74 using OutputImageType = TOutputImage;
75 using MaskImageType = TMaskImage;
76
78 using InputPixelType = typename InputImageType::PixelType;
79 using OutputPixelType = typename OutputImageType::PixelType;
80 using MaskPixelType = typename MaskImageType::PixelType;
81
85
95
96 using typename Superclass::HistogramType;
98
100 static constexpr unsigned int InputImageDimension = InputImageType::ImageDimension;
101 static constexpr unsigned int OutputImageDimension = OutputImageType::ImageDimension;
102
105 itkSetMacro(ReturnBinMidpoint, bool);
106 itkGetConstReferenceMacro(ReturnBinMidpoint, bool);
107 itkBooleanMacro(ReturnBinMidpoint);
110protected:
111 OtsuThresholdImageFilter() { this->SetCalculator(CalculatorType::New()); }
112 ~OtsuThresholdImageFilter() override = default;
113
114 void
115 GenerateData() override
116 {
117 auto calc = static_cast<CalculatorType *>(this->GetModifiableCalculator());
118 calc->SetReturnBinMidpoint(m_ReturnBinMidpoint);
119 this->Superclass::GenerateData();
120 }
121
122 void
123 VerifyPreconditions() ITKv5_CONST override
124 {
125 Superclass::VerifyPreconditions();
126 if (dynamic_cast<const CalculatorType *>(Superclass::GetCalculator()) == nullptr)
127 {
128 itkExceptionMacro("Invalid OtsuThresholdCalculator.");
129 }
130 }
131
132
133private:
134#if defined(ITKV4_COMPATIBILITY)
135 bool m_ReturnBinMidpoint{ true };
136#else
137 bool m_ReturnBinMidpoint{ false };
138#endif
139};
140
141} // end namespace itk
142
143#endif
Threshold an image using a HistogramThresholdCalculator.
Base class for all process objects that output image data.
typename OutputImageType::RegionType OutputImageRegionType
TOutputImage OutputImageType
typename OutputImageType::Pointer OutputImagePointer
typename InputImageType::Pointer InputImagePointer
typename InputImageType::RegionType InputImageRegionType
Computes the Otsu's threshold for an image.
virtual void SetReturnBinMidpoint(bool _arg)
Threshold an image using the Otsu Threshold.
typename OutputImageType::IndexType OutputIndexType
typename OutputImageType::SizeType OutputSizeType
typename OutputImageType::PixelType OutputPixelType
~OtsuThresholdImageFilter() override=default
typename MaskImageType::SizeType MaskSizeType
typename MaskImageType::RegionType MaskImageRegionType
typename InputImageType::PixelType InputPixelType
typename MaskImageType::PixelType MaskPixelType
typename InputImageType::IndexType InputIndexType
void VerifyPreconditions() ITKv5_CONST override
Verifies that the process object has been configured correctly, that all required inputs are set,...
typename MaskImageType::IndexType MaskIndexType
typename InputImageType::SizeType InputSizeType
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
static Pointer New()
SmartPointer< Self > Pointer
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....