ITK  6.0.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 * 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#ifndef itkBinaryThresholdImageFilter_h
19#define itkBinaryThresholdImageFilter_h
20
22#include "itkConceptChecking.h"
24
25namespace itk
26{
64namespace Functor
65{
66template <typename TInput, typename TOutput>
67class ITK_TEMPLATE_EXPORT BinaryThreshold
68{
69public:
71 {
72 m_LowerThreshold = NumericTraits<TInput>::NonpositiveMin();
73 m_UpperThreshold = NumericTraits<TInput>::max();
74 m_OutsideValue = TOutput{};
75 m_InsideValue = NumericTraits<TOutput>::max();
76 }
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
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
123private:
128};
129} // namespace Functor
130
131template <typename TInputImage, typename TOutputImage>
132class ITK_TEMPLATE_EXPORT BinaryThresholdImageFilter
134 TInputImage,
135 TOutputImage,
136 Functor::BinaryThreshold<typename TInputImage::PixelType, typename TOutputImage::PixelType>>
137{
138public:
139 ITK_DISALLOW_COPY_AND_MOVE(BinaryThresholdImageFilter);
140
144 TInputImage,
145 TOutputImage,
149
151 itkNewMacro(Self);
152
154 itkOverrideGetNameOfClassMacro(BinaryThresholdImageFilter);
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
183
184 virtual void
186
187 virtual void
189
190 virtual void
192
194 virtual InputPixelType
196
197 virtual InputPixelObjectType *
199
200 virtual const InputPixelObjectType *
202
203 virtual InputPixelType
205
206 virtual InputPixelObjectType *
208
209 virtual const InputPixelObjectType *
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
221protected:
223 ~BinaryThresholdImageFilter() override = default;
224 void
225 PrintSelf(std::ostream & os, Indent indent) const override;
226
229 void
231
232private:
233 OutputPixelType m_InsideValue{};
234 OutputPixelType m_OutsideValue{};
235};
236} // end namespace itk
237
238#ifndef ITK_MANUAL_INSTANTIATION
239# include "itkBinaryThresholdImageFilter.hxx"
240#endif
241
242#endif
Binarize an input image by thresholding.
typename TInputImage::PixelType InputPixelType
virtual const InputPixelObjectType * GetLowerThresholdInput() const
void BeforeThreadedGenerateData() override
virtual InputPixelType GetLowerThreshold() const
virtual InputPixelObjectType * GetUpperThresholdInput()
virtual const InputPixelObjectType * GetUpperThresholdInput() const
~BinaryThresholdImageFilter() override=default
virtual void SetUpperThreshold(const InputPixelType threshold)
virtual void SetLowerThreshold(const InputPixelType threshold)
typename TOutputImage::PixelType OutputPixelType
virtual void SetLowerThresholdInput(const InputPixelObjectType *)
virtual void SetUpperThresholdInput(const InputPixelObjectType *)
virtual InputPixelObjectType * GetLowerThresholdInput()
virtual InputPixelType GetUpperThreshold() const
void PrintSelf(std::ostream &os, Indent indent) const override
void SetUpperThreshold(const TInput &thresh)
void SetLowerThreshold(const TInput &thresh)
void SetInsideValue(const TOutput &value)
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(BinaryThreshold)
bool operator==(const BinaryThreshold &other) const
TOutput operator()(const TInput &A) const
void SetOutsideValue(const TOutput &value)
Base class for all process objects that output image data.
Control indentation during Print() invocation.
Definition: itkIndent.h:50
static constexpr T NonpositiveMin()
static constexpr T max(const T &)
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Decorates any "simple" data type (data types without smart pointers) with a DataObject API.
Implements pixel-wise generic operation on one image.
#define itkConceptMacro(name, concept)
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:726
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....