18#ifndef itkShapeKeepNObjectsLabelMapFilter_h
19#define itkShapeKeepNObjectsLabelMapFilter_h
43template <
typename TImage>
66 static constexpr unsigned int ImageDimension = TImage::ImageDimension;
74#ifdef ITK_USE_CONCEPT_CHECKING
90 itkSetMacro(ReverseOrdering,
bool);
91 itkGetConstReferenceMacro(ReverseOrdering,
bool);
92 itkBooleanMacro(ReverseOrdering);
113 this->SetAttribute(LabelObjectType::GetAttributeFromName(s));
123 template <
typename TAttributeAccessor>
128 this->AllocateOutputs();
131 ImageType * output2 = this->GetOutput(1);
135 output2->SetBackgroundValue(output->GetBackgroundValue());
138 using VectorType = std::vector<LabelObjectPointer>;
144 labelObjects.reserve(output->GetNumberOfLabelObjects());
145 typename ImageType::Iterator it(output);
146 while (!it.IsAtEnd())
148 labelObjects.push_back(it.GetLabelObject());
154 if (m_NumberOfObjects < output->GetNumberOfLabelObjects())
156 auto end = labelObjects.begin() + m_NumberOfObjects;
157 if (m_ReverseOrdering)
160 std::nth_element(labelObjects.begin(), end, labelObjects.end(), comparator);
165 std::nth_element(labelObjects.begin(), end, labelObjects.end(), comparator);
170 for (
typename VectorType::const_iterator it2 = end; it2 != labelObjects.end(); ++it2)
172 output2->AddLabelObject(*it2);
173 output->RemoveLabelObject(*it2);
182 bool m_ReverseOrdering{};
189#ifndef ITK_MANUAL_INSTANTIATION
190# include "itkShapeKeepNObjectsLabelMapFilter.hxx"
Base class for filters that takes an image as input and overwrites that image as the output.
Control indentation during Print() invocation.
Light weight base class for most itk classes.
Implements progress tracking for a filter.
Keep N objects according to their shape attributes.
typename ImageType::PixelType PixelType
typename ImageType::Pointer ImagePointer
typename ImageType::ConstPointer ImageConstPointer
void SetAttribute(const std::string &s)
~ShapeKeepNObjectsLabelMapFilter() override=default
typename LabelObjectType::AttributeType AttributeType
void PrintSelf(std::ostream &os, Indent indent) const override
void TemplatedGenerateData(const TAttributeAccessor &)
ShapeKeepNObjectsLabelMapFilter()
void GenerateData() override
typename ImageType::LabelObjectType LabelObjectType
typename ImageType::IndexType IndexType
SmartPointer< const Self > ConstPointer
SmartPointer< Self > Pointer
ImageBaseType::IndexType IndexType
ImageBaseType::SpacingType VectorType
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType