ITK  6.0.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 * 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/*=========================================================================
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
35namespace itk
36{
51namespace Functor
52{
53template <typename TInput>
55{
56public:
57 SimilarPixelsFunctor() { m_Threshold = TInput{}; }
59 ~SimilarPixelsFunctor() = default;
60
61 bool
62 operator==(const SimilarPixelsFunctor & other) const
63 {
64 return m_Threshold == other.m_Threshold;
65 }
68
69 void
70 SetDistanceThreshold(const TInput & thresh)
71 {
72 m_Threshold = thresh;
73 }
74
75 TInput
77 {
78 return (m_Threshold);
79 }
80
81 bool
82 operator()(const TInput & a, const TInput & b) const
83 {
84 using InputRealType = typename NumericTraits<TInput>::RealType;
85 auto absDifference =
86 static_cast<TInput>(itk::Math::abs(static_cast<InputRealType>(a) - static_cast<InputRealType>(b)));
87 if (absDifference <= m_Threshold)
88 {
89 return true;
90 }
91
92 return false;
93 }
94
95protected:
96 TInput m_Threshold;
97};
98} // end namespace Functor
99
100template <typename TInputImage, typename TOutputImage, typename TMaskImage = TInputImage>
102 : public ConnectedComponentFunctorImageFilter<TInputImage,
103 TOutputImage,
104 Functor::SimilarPixelsFunctor<typename TInputImage::ValueType>,
105 TMaskImage>
106{
107public:
108 ITK_DISALLOW_COPY_AND_MOVE(ScalarConnectedComponentImageFilter);
109
112 using Superclass =
114 TOutputImage,
116 TMaskImage>;
120
122 itkNewMacro(Self);
123
125 itkOverrideGetNameOfClassMacro(ScalarConnectedComponentImageFilter);
127 using InputPixelType = typename TInputImage::PixelType;
128
129 virtual void
131 {
132 this->GetFunctor().SetDistanceThreshold(thresh);
133 }
134
137 {
138 return (this->GetFunctor().GetDistanceThreshold());
139 }
140
141#ifdef ITK_USE_CONCEPT_CHECKING
142 // Begin concept checking
143 itkConceptMacro(InputEqualityComparableCheck, (Concept::EqualityComparable<InputPixelType>));
146 itkConceptMacro(OutputIncrementDecrementOperatorsCheck,
148 // End concept checking
149#endif
150
151protected:
153 ~ScalarConnectedComponentImageFilter() override = default;
154};
155} // end namespace itk
156
157#endif
A generic connected components filter that labels the objects in an arbitrary image.
bool operator==(const SimilarPixelsFunctor &other) const
bool operator()(const TInput &a, const TInput &b) const
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(SimilarPixelsFunctor)
Base class for all process objects that output image data.
Define additional traits for native types such as int or float.
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
A connected components filter that labels the objects in an arbitrary image. Two pixels are similar i...
virtual void SetDistanceThreshold(const InputPixelType &thresh)
~ScalarConnectedComponentImageFilter() override=default
typename TInputImage::PixelType InputPixelType
#define itkConceptMacro(name, concept)
bool abs(bool x)
Definition: itkMath.h:839
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....