ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkScalarConnectedComponentImageFilter.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 /*=========================================================================
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 {
50 namespace Functor
51 {
52 template< typename TInput >
54 {
55 public:
57  {
59  }
60 
61  ~SimilarPixelsFunctor() = default;
62 
63  bool operator!=(const SimilarPixelsFunctor & other) const
64  {
65  if ( m_Threshold != other.m_Threshold )
66  {
67  return true;
68  }
69  return false;
70  }
71 
72  bool operator==(const SimilarPixelsFunctor & other) const
73  {
74  return !( *this != other );
75  }
76 
77  void SetDistanceThreshold(const TInput & thresh)
78  {
79  m_Threshold = thresh;
80  }
81 
83  {
84  return ( m_Threshold );
85  }
86 
87  bool operator()(const TInput & a, const TInput & b) const
88  {
89  using InputRealType = typename NumericTraits< TInput >::RealType;
90  auto absDifference = static_cast< TInput >( itk::Math::abs(
91  static_cast< InputRealType >( a )
92  - static_cast< InputRealType >( b ) ) );
93  if ( absDifference <= m_Threshold )
94  {
95  return true;
96  }
97  else
98  {
99  return false;
100  }
101  }
102 
103 protected:
104  TInput m_Threshold;
105 };
106 } // end namespace Functor
107 
108 template< typename TInputImage, typename TOutputImage, typename TMaskImage = TInputImage >
110  public ConnectedComponentFunctorImageFilter< TInputImage, TOutputImage,
111  Functor::SimilarPixelsFunctor< typename TInputImage::ValueType >,
112  TMaskImage >
113 {
114 public:
115  ITK_DISALLOW_COPY_AND_ASSIGN(ScalarConnectedComponentImageFilter);
116 
120  TInputImage, TOutputImage,
122  TMaskImage >;
123 
126 
128  itkNewMacro(Self);
129 
132 
133  using InputPixelType = typename TInputImage::PixelType;
134 
135  virtual void SetDistanceThreshold(const InputPixelType & thresh)
136  { this->GetFunctor().SetDistanceThreshold(thresh); }
137 
139  { return ( this->GetFunctor().GetDistanceThreshold() ); }
140 
141 #ifdef ITK_USE_CONCEPT_CHECKING
142  // Begin concept checking
143  itkConceptMacro( InputEqualityComparableCheck,
145  itkConceptMacro( OutputEqualityComparableCheck,
147  itkConceptMacro( MaskEqualityComparableCheck,
149  itkConceptMacro( OutputIncrementDecrementOperatorsCheck,
151  // End concept checking
152 #endif
153 
154 protected:
156  ~ScalarConnectedComponentImageFilter() override = default;
157 };
158 } // end namespace itk
159 
160 #endif
A connected components filter that labels the objects in an arbitrary image. Two pixels are similar i...
Define numeric traits for std::vector.
bool operator!=(const SimilarPixelsFunctor &other) const
A generic connected components filter that labels the objects in an artibitrary image.
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Base class for all process objects that output image data.
~ScalarConnectedComponentImageFilter() override=default
bool operator()(const TInput &a, const TInput &b) const
bool operator==(const SimilarPixelsFunctor &other) const
virtual void SetDistanceThreshold(const InputPixelType &thresh)
#define itkConceptMacro(name, concept)
typename TInputImage::PixelType InputPixelType