ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkBinaryThresholdImageFunction.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 itkBinaryThresholdImageFunction_h
19 #define itkBinaryThresholdImageFunction_h
20 
21 #include "itkImageFunction.h"
22 
23 namespace itk
24 {
42 template< typename TInputImage, typename TCoordRep = float >
43 class ITK_TEMPLATE_EXPORT BinaryThresholdImageFunction:
44  public ImageFunction< TInputImage, bool, TCoordRep >
45 {
46 public:
47  ITK_DISALLOW_COPY_AND_ASSIGN(BinaryThresholdImageFunction);
48 
54 
57 
59  itkNewMacro(Self);
60 
62  using InputImageType = typename Superclass::InputImageType;
63 
65  using PixelType = typename TInputImage::PixelType;
66 
68  static constexpr unsigned int ImageDimension = Superclass::ImageDimension;
69 
71  using PointType = typename Superclass::PointType;
72 
74  using IndexType = typename Superclass::IndexType;
75 
77  using ContinuousIndexType = typename Superclass::ContinuousIndexType;
78 
88  bool Evaluate(const PointType & point) const override
89  {
90  IndexType index;
91 
92  this->ConvertPointToNearestIndex(point, index);
93  return ( this->EvaluateAtIndex(index) );
94  }
95 
105  const ContinuousIndexType & index) const override
106  {
107  IndexType nindex;
108 
109  this->ConvertContinuousIndexToNearestIndex (index, nindex);
110  return this->EvaluateAtIndex(nindex);
111  }
112 
121  bool EvaluateAtIndex(const IndexType & index) const override
122  {
123  PixelType value = this->GetInputImage()->GetPixel(index);
124 
125  return ( m_Lower <= value && value <= m_Upper );
126  }
127 
129  itkGetConstReferenceMacro(Lower, PixelType);
130 
132  itkGetConstReferenceMacro(Upper, PixelType);
133 
135  void ThresholdAbove(PixelType thresh);
136 
138  void ThresholdBelow(PixelType thresh);
139 
141  void ThresholdBetween(PixelType lower, PixelType upper);
142 
143 protected:
145  ~BinaryThresholdImageFunction() override = default;
146  void PrintSelf(std::ostream & os, Indent indent) const override;
147 
148 private:
151 };
152 } // end namespace itk
153 
154 #ifndef ITK_MANUAL_INSTANTIATION
155 #include "itkBinaryThresholdImageFunction.hxx"
156 #endif
157 
158 #endif
Light weight base class for most itk classes.
bool Evaluate(const PointType &point) const override
bool EvaluateAtIndex(const IndexType &index) const override
typename Superclass::ContinuousIndexType ContinuousIndexType
bool EvaluateAtContinuousIndex(const ContinuousIndexType &index) const override
typename Superclass::InputImageType InputImageType
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Returns true is the value of an image lies within a range of thresholds This ImageFunction returns tr...
Evaluates a function of an image at specified position.