ITK  5.2.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  * 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 
19 #ifndef itkOtsuThresholdImageFilter_h
20 #define itkOtsuThresholdImageFilter_h
21 
24 
25 namespace itk
26 {
27 
54 template <typename TInputImage, typename TOutputImage, typename TMaskImage = TOutputImage>
55 class OtsuThresholdImageFilter : public HistogramThresholdImageFilter<TInputImage, TOutputImage, TMaskImage>
56 {
57 public:
58  ITK_DISALLOW_COPY_AND_MOVE(OtsuThresholdImageFilter);
59 
65 
67  itkNewMacro(Self);
68 
71 
72  using InputImageType = TInputImage;
73  using OutputImageType = TOutputImage;
74  using MaskImageType = TMaskImage;
75 
77  using InputPixelType = typename InputImageType::PixelType;
78  using OutputPixelType = typename OutputImageType::PixelType;
79  using MaskPixelType = typename MaskImageType::PixelType;
80 
82  using InputImagePointer = typename InputImageType::Pointer;
83  using OutputImagePointer = typename OutputImageType::Pointer;
84 
94 
97 
99  static constexpr unsigned int InputImageDimension = InputImageType::ImageDimension;
100  static constexpr unsigned int OutputImageDimension = OutputImageType::ImageDimension;
101 
104  itkSetMacro(ReturnBinMidpoint, bool);
105  itkGetConstReferenceMacro(ReturnBinMidpoint, bool);
106  itkBooleanMacro(ReturnBinMidpoint);
108 
109 protected:
111  ~OtsuThresholdImageFilter() override = default;
112 
113  void
114  GenerateData() override
115  {
116  auto calc = static_cast<CalculatorType *>(this->GetModifiableCalculator());
117  calc->SetReturnBinMidpoint(m_ReturnBinMidpoint);
118  this->Superclass::GenerateData();
119  }
120 
121  void
122  VerifyPreconditions() ITKv5_CONST override
123  {
125  if (dynamic_cast<const CalculatorType *>(Superclass::GetCalculator()) == nullptr)
126  {
127  itkExceptionMacro(<< "Invalid OtsuThresholdCalculator.");
128  }
129  }
130 
131 
132 private:
133 #if defined(ITKV4_COMPATIBILITY)
134  bool m_ReturnBinMidpoint{ true };
135 #else
136  bool m_ReturnBinMidpoint{ false };
137 #endif
138 };
139 
140 } // end namespace itk
141 
142 #endif
itk::HistogramThresholdImageFilter::VerifyPreconditions
void VerifyPreconditions() ITKv5_CONST override
Definition: itkHistogramThresholdImageFilter.h:210
itk::HistogramThresholdImageFilter::InputIndexType
typename InputImageType::IndexType InputIndexType
Definition: itkHistogramThresholdImageFilter.h:94
itk::ImageSource::OutputImagePointer
typename OutputImageType::Pointer OutputImagePointer
Definition: itkImageSource.h:91
itk::HistogramThresholdImageFilter::HistogramType
Statistics::Histogram< ValueRealType > HistogramType
Definition: itkHistogramThresholdImageFilter.h:105
itk::HistogramThresholdImageFilter::InputPixelType
typename InputImageType::PixelType InputPixelType
Definition: itkHistogramThresholdImageFilter.h:84
itk::OtsuThresholdImageFilter::OutputImageDimension
static constexpr unsigned int OutputImageDimension
Definition: itkOtsuThresholdImageFilter.h:100
itk::HistogramThresholdImageFilter::MaskImageRegionType
typename MaskImageType::RegionType MaskImageRegionType
Definition: itkHistogramThresholdImageFilter.h:101
itk::HistogramThresholdImageFilter::MaskSizeType
typename MaskImageType::SizeType MaskSizeType
Definition: itkHistogramThresholdImageFilter.h:99
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itk::HistogramThresholdImageFilter::OutputSizeType
typename OutputImageType::SizeType OutputSizeType
Definition: itkHistogramThresholdImageFilter.h:96
itk::HistogramThresholdImageFilter
Threshold an image using a HistogramThresholdCalculator.
Definition: itkHistogramThresholdImageFilter.h:62
itk::HistogramThresholdImageFilter::OutputPixelType
typename OutputImageType::PixelType OutputPixelType
Definition: itkHistogramThresholdImageFilter.h:85
itk::SmartPointer< Self >
itk::OtsuThresholdImageFilter
Threshold an image using the Otsu Threshold.
Definition: itkOtsuThresholdImageFilter.h:55
itk::HistogramThresholdImageFilter::OutputIndexType
typename OutputImageType::IndexType OutputIndexType
Definition: itkHistogramThresholdImageFilter.h:97
itk::HistogramThresholdImageFilter::GetCalculator
virtual const CalculatorType * GetCalculator() const
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::ImageSource
Base class for all process objects that output image data.
Definition: itkImageSource.h:67
itkOtsuThresholdCalculator.h
itk::Statistics::Histogram
This class stores measurement vectors in the context of n-dimensional histogram.
Definition: itkHistogram.h:77
itk::HistogramThresholdImageFilter::GetModifiableCalculator
virtual CalculatorType * GetModifiableCalculator()
itk::ImageToImageFilter::InputImagePointer
typename InputImageType::Pointer InputImagePointer
Definition: itkImageToImageFilter.h:130
itk::OtsuThresholdCalculator
Computes the Otsu's threshold for an image.
Definition: itkOtsuThresholdCalculator.h:45
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::OtsuThresholdImageFilter::InputImageDimension
static constexpr unsigned int InputImageDimension
Definition: itkOtsuThresholdImageFilter.h:99
itk::HistogramThresholdImageFilter::MaskPixelType
typename MaskImageType::PixelType MaskPixelType
Definition: itkHistogramThresholdImageFilter.h:86
itk::ImageToImageFilter::InputImageType
TInputImage InputImageType
Definition: itkImageToImageFilter.h:129
itk::HistogramThresholdImageFilter::InputSizeType
typename InputImageType::SizeType InputSizeType
Definition: itkHistogramThresholdImageFilter.h:93
itk::HistogramThresholdImageFilter::MaskImageType
TMaskImage MaskImageType
Definition: itkHistogramThresholdImageFilter.h:81
itk::OtsuThresholdImageFilter::OtsuThresholdImageFilter
OtsuThresholdImageFilter()
Definition: itkOtsuThresholdImageFilter.h:110
itk::HistogramThresholdCalculator
Base class to compute a threshold value based on the histogram of an image.
Definition: itkHistogramThresholdCalculator.h:46
itk::ImageSource::OutputImageRegionType
typename OutputImageType::RegionType OutputImageRegionType
Definition: itkImageSource.h:92
itk::HistogramThresholdImageFilter::SetCalculator
virtual void SetCalculator(CalculatorType *_arg)
itk::HistogramThresholdImageFilter::GenerateData
void GenerateData() override
itk::HistogramThresholdImageFilter::MaskIndexType
typename MaskImageType::IndexType MaskIndexType
Definition: itkHistogramThresholdImageFilter.h:100
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::OtsuThresholdCalculator::New
static Pointer New()
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:138
itkHistogramThresholdImageFilter.h
itk::OtsuThresholdImageFilter::GenerateData
void GenerateData() override
Definition: itkOtsuThresholdImageFilter.h:114
itk::OtsuThresholdImageFilter::~OtsuThresholdImageFilter
~OtsuThresholdImageFilter() override=default
itk::OtsuThresholdImageFilter::m_ReturnBinMidpoint
bool m_ReturnBinMidpoint
Definition: itkOtsuThresholdImageFilter.h:136
itk::ImageToImageFilter::InputImageRegionType
typename InputImageType::RegionType InputImageRegionType
Definition: itkImageToImageFilter.h:132
itk::OtsuThresholdImageFilter::VerifyPreconditions
void VerifyPreconditions() ITKv5_CONST override
Definition: itkOtsuThresholdImageFilter.h:122
itk::ImageSource::OutputImageType
TOutputImage OutputImageType
Definition: itkImageSource.h:90