ITK  6.0.0
Insight Toolkit
itkShapeOpeningLabelMapFilter.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#ifndef itkShapeOpeningLabelMapFilter_h
19#define itkShapeOpeningLabelMapFilter_h
20
23#include "itkProgressReporter.h"
24
25namespace itk
26{
48template <typename TImage>
49class ITK_TEMPLATE_EXPORT ShapeOpeningLabelMapFilter : public InPlaceLabelMapFilter<TImage>
50{
51public:
52 ITK_DISALLOW_COPY_AND_MOVE(ShapeOpeningLabelMapFilter);
53
59
61 using ImageType = TImage;
64 using PixelType = typename ImageType::PixelType;
66 using LabelObjectType = typename ImageType::LabelObjectType;
67
68 using AttributeType = typename LabelObjectType::AttributeType;
69
71 static constexpr unsigned int ImageDimension = TImage::ImageDimension;
72
74 itkNewMacro(Self);
75
77 itkOverrideGetNameOfClassMacro(ShapeOpeningLabelMapFilter);
78
79#ifdef ITK_USE_CONCEPT_CHECKING
80 // Begin concept checking
81/* itkConceptMacro(InputEqualityComparableCheck,
82 (Concept::EqualityComparable<InputImagePixelType>));
83 itkConceptMacro(IntConvertibleToInputCheck,
84 (Concept::Convertible<int, InputImagePixelType>));
85 itkConceptMacro(InputOStreamWritableCheck,
86 (Concept::OStreamWritable<InputImagePixelType>));*/
87// End concept checking
88#endif
89
93 itkGetConstMacro(Lambda, double);
94 itkSetMacro(Lambda, double);
103 itkGetConstMacro(ReverseOrdering, bool);
104 itkSetMacro(ReverseOrdering, bool);
105 itkBooleanMacro(ReverseOrdering);
112 itkGetConstMacro(Attribute, AttributeType);
113 itkSetMacro(Attribute, AttributeType);
114 void
115 SetAttribute(const std::string & s)
116 {
117 this->SetAttribute(LabelObjectType::GetAttributeFromName(s));
118 }
121protected:
123 ~ShapeOpeningLabelMapFilter() override = default;
124
125 void
126 GenerateData() override;
127
128 template <typename TAttributeAccessor>
129 void
130 TemplatedGenerateData(const TAttributeAccessor & accessor)
131 {
132 // Allocate the output
133 this->AllocateOutputs();
134
135 ImageType * output = this->GetOutput();
136 ImageType * output2 = this->GetOutput(1);
137 itkAssertInDebugAndIgnoreInReleaseMacro(this->GetNumberOfIndexedOutputs() == 2);
138 itkAssertInDebugAndIgnoreInReleaseMacro(output2 != nullptr);
139
140 // set the background value for the second output - this is not done in the
141 // superclasses
142 output2->SetBackgroundValue(output->GetBackgroundValue());
143
144 ProgressReporter progress(this, 0, output->GetNumberOfLabelObjects());
145
146 typename ImageType::Iterator it(output);
147 while (!it.IsAtEnd())
148 {
149 typename LabelObjectType::LabelType label = it.GetLabel();
150 LabelObjectType * labelObject = it.GetLabelObject();
151
152 if ((!m_ReverseOrdering && accessor(labelObject) < m_Lambda) ||
153 (m_ReverseOrdering && accessor(labelObject) > m_Lambda))
154 {
155 // must increment the iterator before removing the object to avoid
156 // invalidating the iterator
157 ++it;
158 output2->AddLabelObject(labelObject);
159 output->RemoveLabel(label);
160 }
161 else
162 {
163 ++it;
164 }
165
166 progress.CompletedPixel();
167 }
168 }
169
170 void
171 PrintSelf(std::ostream & os, Indent indent) const override;
172
173 double m_Lambda{};
174
175 bool m_ReverseOrdering{};
176
177 AttributeType m_Attribute{};
178}; // end of class
179} // end namespace itk
180
181#ifndef ITK_MANUAL_INSTANTIATION
182# include "itkShapeOpeningLabelMapFilter.hxx"
183#endif
184
185#endif
Base class for filters that takes an image as input and overwrites that image as the output.
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
Implements progress tracking for a filter.
Remove objects according to the value of their shape attribute.
typename ImageType::ConstPointer ImageConstPointer
void TemplatedGenerateData(const TAttributeAccessor &accessor)
void PrintSelf(std::ostream &os, Indent indent) const override
typename ImageType::IndexType IndexType
~ShapeOpeningLabelMapFilter() override=default
typename ImageType::LabelObjectType LabelObjectType
typename LabelObjectType::AttributeType AttributeType
typename ImageType::PixelType PixelType
SmartPointer< const Self > ConstPointer
SmartPointer< Self > Pointer
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....