ITK  5.3.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 
103  bool
104  operator==(const BinaryThreshold & other) const
105  {
106  return m_LowerThreshold == other.m_LowerThreshold && m_UpperThreshold == other.m_UpperThreshold &&
107  Math::ExactlyEquals(m_InsideValue, other.m_InsideValue) &&
108  Math::ExactlyEquals(m_OutsideValue, other.m_OutsideValue);
109  }
110 
111  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(BinaryThreshold);
112 
113  inline TOutput
114  operator()(const TInput & A) const
115  {
116  if (m_LowerThreshold <= A && A <= m_UpperThreshold)
117  {
118  return m_InsideValue;
119  }
120  return m_OutsideValue;
121  }
122 
123 private:
126  TOutput m_InsideValue;
127  TOutput m_OutsideValue;
128 };
129 } // namespace Functor
130 
131 template <typename TInputImage, typename TOutputImage>
132 class ITK_TEMPLATE_EXPORT BinaryThresholdImageFilter
133  : public UnaryFunctorImageFilter<
134  TInputImage,
135  TOutputImage,
136  Functor::BinaryThreshold<typename TInputImage::PixelType, typename TOutputImage::PixelType>>
137 {
138 public:
139  ITK_DISALLOW_COPY_AND_MOVE(BinaryThresholdImageFilter);
140 
144  TInputImage,
145  TOutputImage,
149 
151  itkNewMacro(Self);
152 
155 
157  using InputPixelType = typename TInputImage::PixelType;
158  using OutputPixelType = typename TOutputImage::PixelType;
159 
162 
165  itkSetMacro(OutsideValue, OutputPixelType);
166 
168  itkGetConstReferenceMacro(OutsideValue, OutputPixelType);
169 
172  itkSetMacro(InsideValue, OutputPixelType);
173 
175  itkGetConstReferenceMacro(InsideValue, OutputPixelType);
176 
181  virtual void
182  SetUpperThreshold(const InputPixelType threshold);
183 
184  virtual void
185  SetUpperThresholdInput(const InputPixelObjectType *);
186 
187  virtual void
188  SetLowerThreshold(const InputPixelType threshold);
189 
190  virtual void
191  SetLowerThresholdInput(const InputPixelObjectType *);
192 
194  virtual InputPixelType
195  GetUpperThreshold() const;
196 
197  virtual InputPixelObjectType *
198  GetUpperThresholdInput();
199 
200  virtual const InputPixelObjectType *
201  GetUpperThresholdInput() const;
202 
203  virtual InputPixelType
204  GetLowerThreshold() const;
205 
206  virtual InputPixelObjectType *
207  GetLowerThresholdInput();
208 
209  virtual const InputPixelObjectType *
210  GetLowerThresholdInput() const;
211 
212 #ifdef ITK_USE_CONCEPT_CHECKING
213  // Begin concept checking
214  itkConceptMacro(OutputEqualityComparableCheck, (Concept::EqualityComparable<OutputPixelType>));
215  itkConceptMacro(InputPixelTypeComparable, (Concept::Comparable<InputPixelType>));
216  itkConceptMacro(InputOStreamWritableCheck, (Concept::OStreamWritable<InputPixelType>));
217  itkConceptMacro(OutputOStreamWritableCheck, (Concept::OStreamWritable<OutputPixelType>));
218  // End concept checking
219 #endif
220 
221 protected:
223  ~BinaryThresholdImageFilter() override = default;
224  void
225  PrintSelf(std::ostream & os, Indent indent) const override;
226 
229  void
230  BeforeThreadedGenerateData() override;
231 
232 private:
235 };
236 } // end namespace itk
237 
238 #ifndef ITK_MANUAL_INSTANTIATION
239 # include "itkBinaryThresholdImageFilter.hxx"
240 #endif
241 
242 #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:233
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:132
itk::NumericTraits::NonpositiveMin
static constexpr T NonpositiveMin()
Definition: itkNumericTraits.h:97
itk::Functor::BinaryThreshold::SetOutsideValue
void SetOutsideValue(const TOutput &value)
Definition: itkBinaryThresholdImageFilter.h:97
itk::Math::ExactlyEquals
bool ExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Return the result of an exact comparison between two scalar values of potentially different types.
Definition: itkMath.h:723
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::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:104
itk::Functor::BinaryThreshold::m_InsideValue
TOutput m_InsideValue
Definition: itkBinaryThresholdImageFilter.h:126
itk::BinaryThresholdImageFilter::OutputPixelType
typename TOutputImage::PixelType OutputPixelType
Definition: itkBinaryThresholdImageFilter.h:158
itk::BinaryThresholdImageFilter::m_OutsideValue
OutputPixelType m_OutsideValue
Definition: itkBinaryThresholdImageFilter.h:234
itk::Functor::BinaryThreshold::m_LowerThreshold
TInput m_LowerThreshold
Definition: itkBinaryThresholdImageFilter.h:124
itk::Functor::BinaryThreshold::m_OutsideValue
TOutput m_OutsideValue
Definition: itkBinaryThresholdImageFilter.h:127
itk::BinaryThresholdImageFilter::InputPixelType
typename TInputImage::PixelType InputPixelType
Definition: itkBinaryThresholdImageFilter.h:157
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:125
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:114
itkSimpleDataObjectDecorator.h
itk::Concept::EqualityComparable
Definition: itkConceptChecking.h:306
itk::Functor::BinaryThreshold
Definition: itkBinaryThresholdImageFilter.h:67