ITK  5.2.0
Insight Toolkit
itkBinaryThresholdImageFilter.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 itkBinaryThresholdImageFilter_h
19 #define itkBinaryThresholdImageFilter_h
20 
22 #include "itkConceptChecking.h"
24 
25 namespace itk
26 {
64 namespace Functor
65 {
66 template <typename TInput, typename TOutput>
67 class ITK_TEMPLATE_EXPORT BinaryThreshold
68 {
69 public:
71  {
72  m_LowerThreshold = NumericTraits<TInput>::NonpositiveMin();
73  m_UpperThreshold = NumericTraits<TInput>::max();
74  m_OutsideValue = NumericTraits<TOutput>::ZeroValue();
75  m_InsideValue = NumericTraits<TOutput>::max();
76  }
78 
79  ~BinaryThreshold() = default;
80 
81  void
82  SetLowerThreshold(const TInput & thresh)
83  {
84  m_LowerThreshold = thresh;
85  }
86  void
87  SetUpperThreshold(const TInput & thresh)
88  {
89  m_UpperThreshold = thresh;
90  }
91  void
92  SetInsideValue(const TOutput & value)
93  {
94  m_InsideValue = value;
95  }
96  void
97  SetOutsideValue(const TOutput & value)
98  {
99  m_OutsideValue = value;
100  }
101 
102  bool
103  operator!=(const BinaryThreshold & other) const
104  {
105  if (m_LowerThreshold != other.m_LowerThreshold || m_UpperThreshold != other.m_UpperThreshold ||
106  Math::NotExactlyEquals(m_InsideValue, other.m_InsideValue) ||
107  Math::NotExactlyEquals(m_OutsideValue, other.m_OutsideValue))
108  {
109  return true;
110  }
111  return false;
112  }
113 
114  bool
115  operator==(const BinaryThreshold & other) const
116  {
117  return !(*this != other);
118  }
119 
120  inline TOutput
121  operator()(const TInput & A) const
122  {
123  if (m_LowerThreshold <= A && A <= m_UpperThreshold)
124  {
125  return m_InsideValue;
126  }
127  return m_OutsideValue;
128  }
129 
130 private:
133  TOutput m_InsideValue;
134  TOutput m_OutsideValue;
135 };
136 } // namespace Functor
137 
138 template <typename TInputImage, typename TOutputImage>
139 class ITK_TEMPLATE_EXPORT BinaryThresholdImageFilter
140  : public UnaryFunctorImageFilter<
141  TInputImage,
142  TOutputImage,
143  Functor::BinaryThreshold<typename TInputImage::PixelType, typename TOutputImage::PixelType>>
144 {
145 public:
146  ITK_DISALLOW_COPY_AND_MOVE(BinaryThresholdImageFilter);
147 
151  TInputImage,
152  TOutputImage,
156 
158  itkNewMacro(Self);
159 
162 
164  using InputPixelType = typename TInputImage::PixelType;
165  using OutputPixelType = typename TOutputImage::PixelType;
166 
169 
172  itkSetMacro(OutsideValue, OutputPixelType);
173 
175  itkGetConstReferenceMacro(OutsideValue, OutputPixelType);
176 
179  itkSetMacro(InsideValue, OutputPixelType);
180 
182  itkGetConstReferenceMacro(InsideValue, OutputPixelType);
183 
188  virtual void
189  SetUpperThreshold(const InputPixelType threshold);
190 
191  virtual void
192  SetUpperThresholdInput(const InputPixelObjectType *);
193 
194  virtual void
195  SetLowerThreshold(const InputPixelType threshold);
196 
197  virtual void
198  SetLowerThresholdInput(const InputPixelObjectType *);
199 
201  virtual InputPixelType
202  GetUpperThreshold() const;
203 
204  virtual InputPixelObjectType *
205  GetUpperThresholdInput();
206 
207  virtual const InputPixelObjectType *
208  GetUpperThresholdInput() const;
209 
210  virtual InputPixelType
211  GetLowerThreshold() const;
212 
213  virtual InputPixelObjectType *
214  GetLowerThresholdInput();
215 
216  virtual const InputPixelObjectType *
217  GetLowerThresholdInput() const;
218 
219 #ifdef ITK_USE_CONCEPT_CHECKING
220  // Begin concept checking
221  itkConceptMacro(OutputEqualityComparableCheck, (Concept::EqualityComparable<OutputPixelType>));
222  itkConceptMacro(InputPixelTypeComparable, (Concept::Comparable<InputPixelType>));
223  itkConceptMacro(InputOStreamWritableCheck, (Concept::OStreamWritable<InputPixelType>));
224  itkConceptMacro(OutputOStreamWritableCheck, (Concept::OStreamWritable<OutputPixelType>));
225  // End concept checking
226 #endif
227 
228 protected:
230  ~BinaryThresholdImageFilter() override = default;
231  void
232  PrintSelf(std::ostream & os, Indent indent) const override;
233 
236  void
237  BeforeThreadedGenerateData() override;
238 
239 private:
242 };
243 } // end namespace itk
244 
245 #ifndef ITK_MANUAL_INSTANTIATION
246 # include "itkBinaryThresholdImageFilter.hxx"
247 #endif
248 
249 #endif
itk::SimpleDataObjectDecorator
Decorates any "simple" data type (data types without smart pointers) with a DataObject API.
Definition: itkSimpleDataObjectDecorator.h:66
itk::BinaryThresholdImageFilter::m_InsideValue
OutputPixelType m_InsideValue
Definition: itkBinaryThresholdImageFilter.h:240
itkUnaryFunctorImageFilter.h
itk::Concept::OStreamWritable
Definition: itkConceptChecking.h:636
itk::UnaryFunctorImageFilter
Implements pixel-wise generic operation on one image.
Definition: itkUnaryFunctorImageFilter.h:50
itk::BinaryThresholdImageFilter
Binarize an input image by thresholding.
Definition: itkBinaryThresholdImageFilter.h:139
itk::NumericTraits::NonpositiveMin
static constexpr T NonpositiveMin()
Definition: itkNumericTraits.h:97
itk::Functor::BinaryThreshold::SetOutsideValue
void SetOutsideValue(const TOutput &value)
Definition: itkBinaryThresholdImageFilter.h:97
itkConceptChecking.h
itk::Functor::BinaryThreshold::SetInsideValue
void SetInsideValue(const TOutput &value)
Definition: itkBinaryThresholdImageFilter.h:92
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::Math::NotExactlyEquals
bool NotExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Definition: itkMath.h:733
itk::Functor::BinaryThreshold::SetUpperThreshold
void SetUpperThreshold(const TInput &thresh)
Definition: itkBinaryThresholdImageFilter.h:87
itk::Functor::BinaryThreshold::BinaryThreshold
BinaryThreshold()
Definition: itkBinaryThresholdImageFilter.h:70
itk::ImageSource
Base class for all process objects that output image data.
Definition: itkImageSource.h:67
itk::Functor::BinaryThreshold::operator==
bool operator==(const BinaryThreshold &other) const
Definition: itkBinaryThresholdImageFilter.h:115
itk::Functor::BinaryThreshold::m_InsideValue
TOutput m_InsideValue
Definition: itkBinaryThresholdImageFilter.h:133
itk::BinaryThresholdImageFilter::OutputPixelType
typename TOutputImage::PixelType OutputPixelType
Definition: itkBinaryThresholdImageFilter.h:165
itk::BinaryThresholdImageFilter::m_OutsideValue
OutputPixelType m_OutsideValue
Definition: itkBinaryThresholdImageFilter.h:241
itk::Functor::BinaryThreshold::m_LowerThreshold
TInput m_LowerThreshold
Definition: itkBinaryThresholdImageFilter.h:131
itk::Functor::BinaryThreshold::m_OutsideValue
TOutput m_OutsideValue
Definition: itkBinaryThresholdImageFilter.h:134
itk::BinaryThresholdImageFilter::InputPixelType
typename TInputImage::PixelType InputPixelType
Definition: itkBinaryThresholdImageFilter.h:164
itk::Concept::Comparable
Definition: itkConceptChecking.h:330
itk::Functor::BinaryThreshold::SetLowerThreshold
void SetLowerThreshold(const TInput &thresh)
Definition: itkBinaryThresholdImageFilter.h:82
itk::NumericTraits::max
static constexpr T max(const T &)
Definition: itkNumericTraits.h:167
itk::NumericTraits::ZeroValue
static T ZeroValue()
Definition: itkNumericTraits.h:148
itk::Functor::BinaryThreshold::m_UpperThreshold
TInput m_UpperThreshold
Definition: itkBinaryThresholdImageFilter.h:132
itkConceptMacro
#define itkConceptMacro(name, concept)
Definition: itkConceptChecking.h:65
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:138
itk::Functor::BinaryThreshold::operator()
TOutput operator()(const TInput &A) const
Definition: itkBinaryThresholdImageFilter.h:121
itkSimpleDataObjectDecorator.h
itk::Functor::BinaryThreshold::operator!=
bool operator!=(const BinaryThreshold &other) const
Definition: itkBinaryThresholdImageFilter.h:103
itk::Concept::EqualityComparable
Definition: itkConceptChecking.h:306
itk::Functor::BinaryThreshold
Definition: itkBinaryThresholdImageFilter.h:67