ITK  6.0.0
Insight Toolkit
itkRelabelComponentImageFilter.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 itkRelabelComponentImageFilter_h
19#define itkRelabelComponentImageFilter_h
20
22#include "itkImage.h"
23#include <vector>
24#include <mutex>
25
26namespace itk
27{
81template <typename TInputImage, typename TOutputImage>
82class ITK_TEMPLATE_EXPORT RelabelComponentImageFilter : public InPlaceImageFilter<TInputImage, TOutputImage>
83{
84public:
85 ITK_DISALLOW_COPY_AND_MOVE(RelabelComponentImageFilter);
86
92
96 using typename Superclass::InputImagePointer;
97
102 using OutputPixelType = typename TOutputImage::PixelType;
103 using OutputInternalPixelType = typename TOutputImage::InternalPixelType;
104 using InputPixelType = typename TInputImage::PixelType;
105 using InputInternalPixelType = typename TInputImage::InternalPixelType;
106 static constexpr unsigned int ImageDimension = TOutputImage::ImageDimension;
107 static constexpr unsigned int InputImageDimension = TInputImage::ImageDimension;
108
112 using InputImageType = TInputImage;
113 using OutputImageType = TOutputImage;
116 using RegionType = typename TOutputImage::RegionType;
117
123
127 itkOverrideGetNameOfClassMacro(RelabelComponentImageFilter);
128
132 itkNewMacro(Self);
133
136
139
142 itkGetConstMacro(NumberOfObjects, SizeValueType);
144 using ObjectSizeInPixelsContainerType = std::vector<ObjectSizeType>;
145 using ObjectSizeInPhysicalUnitsContainerType = std::vector<float>;
146
152 itkGetConstMacro(OriginalNumberOfObjects, SizeValueType);
153
156 itkSetMacro(NumberOfObjectsToPrint, SizeValueType);
157 itkGetConstReferenceMacro(NumberOfObjectsToPrint, SizeValueType);
166 itkSetMacro(MinimumObjectSize, ObjectSizeType);
167
173 itkGetConstMacro(MinimumObjectSize, ObjectSizeType);
174
177 itkSetMacro(SortByObjectSize, bool);
178 itkGetConstMacro(SortByObjectSize, bool);
179 itkBooleanMacro(SortByObjectSize);
188 GetSizeOfObjectsInPixels() const
189 {
190 // The GetConstReferenceMacro can't be used here because this container
191 // doesn't have an ostream<< operator overloaded.
192 return this->m_SizeOfObjectsInPixels;
193 }
194
201 GetSizeOfObjectsInPhysicalUnits() const
202 {
203 // The GetConstReferenceMacro can't be used here because this container
204 // doesn't have an ostream<< operator overloaded.
205 return this->m_SizeOfObjectsInPhysicalUnits;
206 }
207
212 GetSizeOfObjectInPixels(LabelType obj) const
213 {
214 if (obj > 0 && static_cast<SizeValueType>(obj) <= m_NumberOfObjects)
215 {
216 return m_SizeOfObjectsInPixels[obj - 1];
217 }
218 else
219 {
220 return 0;
221 }
222 }
228 float
229 GetSizeOfObjectInPhysicalUnits(LabelType obj) const
230 {
231 if (obj > 0 && static_cast<SizeValueType>(obj) <= m_NumberOfObjects)
232 {
233 return m_SizeOfObjectsInPhysicalUnits[obj - 1];
234 }
235 else
236 {
237 return 0;
238 }
239 }
242#ifdef ITK_USE_CONCEPT_CHECKING
243 // Begin concept checking
244 itkConceptMacro(InputEqualityComparableCheck, (Concept::EqualityComparable<InputPixelType>));
245 itkConceptMacro(UnsignedLongConvertibleToInputCheck, (Concept::Convertible<LabelType, InputPixelType>));
246 itkConceptMacro(OutputLongConvertibleToUnsignedLongCheck, (Concept::Convertible<OutputPixelType, LabelType>));
249 // End concept checking
250#endif
251
252protected:
254 ~RelabelComponentImageFilter() override = default;
255
259 void
260 GenerateData() override;
261
262 void
263 ParallelComputeLabels(const RegionType & inputRegionForThread);
264
268 void
269 GenerateInputRequestedRegion() override;
270
272 void
273 PrintSelf(std::ostream & os, Indent indent) const override;
277 ObjectSizeType m_SizeInPixels;
278
280 operator+=(const RelabelComponentObjectType & other)
281 {
282 this->m_SizeInPixels += other.m_SizeInPixels;
283 return *this;
284 }
285 };
286
287private:
288 SizeValueType m_NumberOfObjects{ 0 };
289 SizeValueType m_NumberOfObjectsToPrint{ 10 };
290 SizeValueType m_OriginalNumberOfObjects{ 0 };
291 ObjectSizeType m_MinimumObjectSize{ 0 };
292 bool m_SortByObjectSize{ true };
294 std::mutex m_Mutex{};
296 using MapType = std::map<LabelType, RelabelComponentObjectType>;
297 MapType m_SizeMap{};
299 ObjectSizeInPixelsContainerType m_SizeOfObjectsInPixels{};
300 ObjectSizeInPhysicalUnitsContainerType m_SizeOfObjectsInPhysicalUnits{};
301};
302} // end namespace itk
303
304#ifndef ITK_MANUAL_INSTANTIATION
305# include "itkRelabelComponentImageFilter.hxx"
306#endif
307
308#endif
Base class for all process objects that output image data.
TOutputImage OutputImageType
Base class for filters that take an image as input and overwrite that image as the output.
Control indentation during Print() invocation.
Definition: itkIndent.h:50
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Relabel the components in an image such that consecutive labels are used.
std::map< LabelType, RelabelComponentObjectType > MapType
typename TOutputImage::RegionType RegionType
typename TOutputImage::InternalPixelType OutputInternalPixelType
typename TOutputImage::PixelType OutputPixelType
std::vector< ObjectSizeType > ObjectSizeInPixelsContainerType
typename TInputImage::IndexType IndexType
typename TInputImage::InternalPixelType InputInternalPixelType
typename TInputImage::PixelType InputPixelType
#define itkConceptMacro(name, concept)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType
Definition: itkIntTypes.h:86