ITK  5.2.0
Insight Toolkit
itkScalarConnectedComponentImageFilter.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 /*=========================================================================
19  *
20  * Portions of this file are subject to the VTK Toolkit Version 3 copyright.
21  *
22  * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
23  *
24  * For complete copyright, license and disclaimer of warranty information
25  * please refer to the NOTICE file at the top of the ITK source tree.
26  *
27  *=========================================================================*/
28 #ifndef itkScalarConnectedComponentImageFilter_h
29 #define itkScalarConnectedComponentImageFilter_h
30 
31 #include "itkMath.h"
32 #include "itkNumericTraits.h"
34 
35 namespace itk
36 {
51 namespace Functor
52 {
53 template <typename TInput>
55 {
56 public:
58 
59  ~SimilarPixelsFunctor() = default;
60 
61  bool
62  operator!=(const SimilarPixelsFunctor & other) const
63  {
64  if (m_Threshold != other.m_Threshold)
65  {
66  return true;
67  }
68  return false;
69  }
70 
71  bool
72  operator==(const SimilarPixelsFunctor & other) const
73  {
74  return !(*this != other);
75  }
76 
77  void
78  SetDistanceThreshold(const TInput & thresh)
79  {
80  m_Threshold = thresh;
81  }
82 
83  TInput
85  {
86  return (m_Threshold);
87  }
88 
89  bool
90  operator()(const TInput & a, const TInput & b) const
91  {
92  using InputRealType = typename NumericTraits<TInput>::RealType;
93  auto absDifference =
94  static_cast<TInput>(itk::Math::abs(static_cast<InputRealType>(a) - static_cast<InputRealType>(b)));
95  if (absDifference <= m_Threshold)
96  {
97  return true;
98  }
99  else
100  {
101  return false;
102  }
103  }
104 
105 protected:
106  TInput m_Threshold;
107 };
108 } // end namespace Functor
109 
110 template <typename TInputImage, typename TOutputImage, typename TMaskImage = TInputImage>
112  : public ConnectedComponentFunctorImageFilter<TInputImage,
113  TOutputImage,
114  Functor::SimilarPixelsFunctor<typename TInputImage::ValueType>,
115  TMaskImage>
116 {
117 public:
118  ITK_DISALLOW_COPY_AND_MOVE(ScalarConnectedComponentImageFilter);
119 
122  using Superclass =
124  TOutputImage,
126  TMaskImage>;
127 
130 
132  itkNewMacro(Self);
133 
136 
137  using InputPixelType = typename TInputImage::PixelType;
138 
139  virtual void
141  {
142  this->GetFunctor().SetDistanceThreshold(thresh);
143  }
144 
145  virtual InputPixelType
147  {
148  return (this->GetFunctor().GetDistanceThreshold());
149  }
150 
151 #ifdef ITK_USE_CONCEPT_CHECKING
152  // Begin concept checking
153  itkConceptMacro(InputEqualityComparableCheck, (Concept::EqualityComparable<InputPixelType>));
156  itkConceptMacro(OutputIncrementDecrementOperatorsCheck,
158  // End concept checking
159 #endif
160 
161 protected:
163  ~ScalarConnectedComponentImageFilter() override = default;
164 };
165 } // end namespace itk
166 
167 #endif
itk::ScalarConnectedComponentImageFilter
A connected components filter that labels the objects in an arbitrary image. Two pixels are similar i...
Definition: itkScalarConnectedComponentImageFilter.h:111
itk::ConnectedComponentFunctorImageFilter
A generic connected components filter that labels the objects in an arbitrary image.
Definition: itkConnectedComponentFunctorImageFilter.h:54
itk::Functor::SimilarPixelsFunctor::SimilarPixelsFunctor
SimilarPixelsFunctor()
Definition: itkScalarConnectedComponentImageFilter.h:57
itk::ScalarConnectedComponentImageFilter::ScalarConnectedComponentImageFilter
ScalarConnectedComponentImageFilter()=default
itk::ScalarConnectedComponentImageFilter::~ScalarConnectedComponentImageFilter
~ScalarConnectedComponentImageFilter() override=default
itk::SmartPointer< Self >
itk::Functor::SimilarPixelsFunctor::~SimilarPixelsFunctor
~SimilarPixelsFunctor()=default
itk::ScalarConnectedComponentImageFilter::GetDistanceThreshold
virtual InputPixelType GetDistanceThreshold()
Definition: itkScalarConnectedComponentImageFilter.h:146
itk::Functor::SimilarPixelsFunctor::m_Threshold
TInput m_Threshold
Definition: itkScalarConnectedComponentImageFilter.h:106
itk::ImageSource
Base class for all process objects that output image data.
Definition: itkImageSource.h:67
itk::ScalarConnectedComponentImageFilter::InputPixelType
typename TInputImage::PixelType InputPixelType
Definition: itkScalarConnectedComponentImageFilter.h:137
itk::ScanlineFilterCommon::InputPixelType
typename TInputImage::PixelType InputPixelType
Definition: itkScanlineFilterCommon.h:78
itk::ConnectedComponentFunctorImageFilter< TInputImage, TOutputImage, Functor::SimilarPixelsFunctor< TInputImage::ValueType >, TMaskImage >::GetFunctor
FunctorType & GetFunctor()
Definition: itkConnectedComponentFunctorImageFilter.h:117
itk::NumericTraits
Define additional traits for native types such as int or float.
Definition: itkNumericTraits.h:58
itk::NumericTraits::ZeroValue
static T ZeroValue()
Definition: itkNumericTraits.h:148
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
itkConnectedComponentFunctorImageFilter.h
itk::Functor::SimilarPixelsFunctor::operator==
bool operator==(const SimilarPixelsFunctor &other) const
Definition: itkScalarConnectedComponentImageFilter.h:72
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:138
itk::ScalarConnectedComponentImageFilter::SetDistanceThreshold
virtual void SetDistanceThreshold(const InputPixelType &thresh)
Definition: itkScalarConnectedComponentImageFilter.h:140
itk::Functor::SimilarPixelsFunctor::SetDistanceThreshold
void SetDistanceThreshold(const TInput &thresh)
Definition: itkScalarConnectedComponentImageFilter.h:78
itkNumericTraits.h
itk::Functor::SimilarPixelsFunctor::operator()
bool operator()(const TInput &a, const TInput &b) const
Definition: itkScalarConnectedComponentImageFilter.h:90
itk::Functor::SimilarPixelsFunctor::GetDistanceThreshold
TInput GetDistanceThreshold()
Definition: itkScalarConnectedComponentImageFilter.h:84
itk::Functor::SimilarPixelsFunctor
Definition: itkScalarConnectedComponentImageFilter.h:54
itk::Concept::IncrementDecrementOperators
Definition: itkConceptChecking.h:615
itk::Functor::SimilarPixelsFunctor::operator!=
bool operator!=(const SimilarPixelsFunctor &other) const
Definition: itkScalarConnectedComponentImageFilter.h:62
itkMath.h
itk::Concept::EqualityComparable
Definition: itkConceptChecking.h:306