ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkBinaryThresholdImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 {
63 namespace Functor
64 {
65 template< typename TInput, typename TOutput >
66 class ITK_TEMPLATE_EXPORT BinaryThreshold
67 {
68 public:
70  {
71  m_LowerThreshold = NumericTraits< TInput >::NonpositiveMin();
72  m_UpperThreshold = NumericTraits< TInput >::max();
74  m_InsideValue = NumericTraits< TOutput >::max();
75  }
76 
78 
79  void SetLowerThreshold(const TInput & thresh)
80  { m_LowerThreshold = thresh; }
81  void SetUpperThreshold(const TInput & thresh)
82  { m_UpperThreshold = thresh; }
83  void SetInsideValue(const TOutput & value)
84  { m_InsideValue = value; }
85  void SetOutsideValue(const TOutput & value)
86  { m_OutsideValue = value; }
87 
88  bool operator!=(const BinaryThreshold & other) const
89  {
90  if ( m_LowerThreshold != other.m_LowerThreshold
91  || m_UpperThreshold != other.m_UpperThreshold
92  || Math::NotExactlyEquals( m_InsideValue, other.m_InsideValue )
94  {
95  return true;
96  }
97  return false;
98  }
99 
100  bool operator==(const BinaryThreshold & other) const
101  {
102  return !( *this != other );
103  }
104 
105  inline TOutput operator()(const TInput & A) const
106  {
107  if ( m_LowerThreshold <= A && A <= m_UpperThreshold )
108  {
109  return m_InsideValue;
110  }
111  return m_OutsideValue;
112  }
113 
114 private:
117  TOutput m_InsideValue;
118  TOutput m_OutsideValue;
119 };
120 }
121 
122 template< typename TInputImage, typename TOutputImage >
123 class ITK_TEMPLATE_EXPORT BinaryThresholdImageFilter:
124  public
125  UnaryFunctorImageFilter< TInputImage, TOutputImage,
126  Functor::BinaryThreshold<
127  typename TInputImage::PixelType,
128  typename TOutputImage::PixelType > >
129 {
130 public:
133  typedef UnaryFunctorImageFilter< TInputImage, TOutputImage,
135  typename TInputImage::PixelType,
136  typename TOutputImage::PixelType >
140 
142  itkNewMacro(Self);
143 
146 
148  typedef typename TInputImage::PixelType InputPixelType;
149  typedef typename TOutputImage::PixelType OutputPixelType;
150 
153 
156  itkSetMacro(OutsideValue, OutputPixelType);
157 
159  itkGetConstReferenceMacro(OutsideValue, OutputPixelType);
160 
163  itkSetMacro(InsideValue, OutputPixelType);
164 
166  itkGetConstReferenceMacro(InsideValue, OutputPixelType);
167 
172  virtual void SetUpperThreshold(const InputPixelType threshold);
173 
174  virtual void SetUpperThresholdInput(const InputPixelObjectType *);
175 
176  virtual void SetLowerThreshold(const InputPixelType threshold);
177 
178  virtual void SetLowerThresholdInput(const InputPixelObjectType *);
179 
181  virtual InputPixelType GetUpperThreshold() const;
182 
183  virtual InputPixelObjectType * GetUpperThresholdInput();
184 
185  virtual const InputPixelObjectType * GetUpperThresholdInput() const;
186 
187  virtual InputPixelType GetLowerThreshold() const;
188 
189  virtual InputPixelObjectType * GetLowerThresholdInput();
190 
191  virtual const InputPixelObjectType * GetLowerThresholdInput() const;
192 
193 #ifdef ITK_USE_CONCEPT_CHECKING
194  // Begin concept checking
195  itkConceptMacro( OutputEqualityComparableCheck,
197  itkConceptMacro( InputPixelTypeComparable,
199  itkConceptMacro( InputOStreamWritableCheck,
201  itkConceptMacro( OutputOStreamWritableCheck,
203  // End concept checking
204 #endif
205 
206 protected:
208  virtual ~BinaryThresholdImageFilter() ITK_OVERRIDE {}
209  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
210 
213  virtual void BeforeThreadedGenerateData() ITK_OVERRIDE;
214 
215 private:
216  ITK_DISALLOW_COPY_AND_ASSIGN(BinaryThresholdImageFilter);
217 
218  OutputPixelType m_InsideValue;
220 };
221 } // end namespace itk
222 
223 #ifndef ITK_MANUAL_INSTANTIATION
224 #include "itkBinaryThresholdImageFilter.hxx"
225 #endif
226 
227 #endif
void SetUpperThreshold(const TInput &thresh)
TOutput operator()(const TInput &A) const
Base class for all process objects that output image data.
bool operator==(const BinaryThreshold &other) const
Binarize an input image by thresholding.
static ITK_CONSTEXPR_FUNC T max(const T &)
Decorates any &quot;simple&quot; data type (data types without smart pointers) with a DataObject API...
void SetInsideValue(const TOutput &value)
UnaryFunctorImageFilter< TInputImage, TOutputImage, Functor::BinaryThreshold< typename TInputImage::PixelType, typename TOutputImage::PixelType > > Superclass
bool NotExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Definition: itkMath.h:721
static ITK_CONSTEXPR_FUNC T NonpositiveMin()
Implements pixel-wise generic operation on one image.
TOutput m_OutsideValue
void SetOutsideValue(const TOutput &value)
Control indentation during Print() invocation.
Definition: itkIndent.h:49
void SetLowerThreshold(const TInput &thresh)
SimpleDataObjectDecorator< InputPixelType > InputPixelObjectType
#define itkConceptMacro(name, concept)
bool operator!=(const BinaryThreshold &other) const