18 #ifndef itkShapeKeepNObjectsLabelMapFilter_h
19 #define itkShapeKeepNObjectsLabelMapFilter_h
43 template<
typename TImage >
73 #ifdef ITK_USE_CONCEPT_CHECKING
89 itkSetMacro(ReverseOrdering,
bool);
90 itkGetConstReferenceMacro(ReverseOrdering,
bool);
91 itkBooleanMacro(ReverseOrdering);
111 this->
SetAttribute( LabelObjectType::GetAttributeFromName(s) );
120 template< typename TAttributeAccessor >
131 output2->SetBackgroundValue( output->GetBackgroundValue() );
133 typedef typename LabelObjectType::Pointer LabelObjectPointer;
134 typedef std::vector< LabelObjectPointer > VectorType;
136 ProgressReporter progress(
this, 0, 2 * output->GetNumberOfLabelObjects() );
139 VectorType labelObjects;
140 labelObjects.reserve( output->GetNumberOfLabelObjects() );
141 typename ImageType::Iterator it( output );
142 while ( ! it.IsAtEnd() )
144 labelObjects.push_back( it.GetLabelObject() );
145 progress.CompletedPixel();
150 if ( m_NumberOfObjects < output->GetNumberOfLabelObjects() )
156 std::nth_element(labelObjects.begin(), end, labelObjects.end(), comparator);
161 std::nth_element(labelObjects.begin(), end, labelObjects.end(), comparator);
163 progress.CompletedPixel();
166 for (
typename VectorType::const_iterator it2 = end;
167 it2 != labelObjects.end();
170 output2->AddLabelObject(*it2);
171 output->RemoveLabelObject(*it2);
172 progress.CompletedPixel();
186 void operator=(const
Self &) ITK_DELETE_FUNCTION;
190 #ifndef ITK_MANUAL_INSTANTIATION
191 #include "itkShapeKeepNObjectsLabelMapFilter.hxx"
ImageType::ConstPointer ImageConstPointer
Light weight base class for most itk classes.
static const unsigned int ImageDimension
virtual void SetAttribute(AttributeType _arg)
void PrintSelf(std::ostream &os, Indent indent) const override
InPlaceLabelMapFilter< TImage > Superclass
virtual void AllocateOutputs() override
SizeValueType m_NumberOfObjects
unsigned long SizeValueType
void TemplatedGenerateData(const TAttributeAccessor &)
ShapeKeepNObjectsLabelMapFilter()
Base class for filters that takes an image as input and overwrites that image as the output...
ImageType::Pointer ImagePointer
Implements progress tracking for a filter.
Keep N objects according to their shape attributes.
LabelObjectType::AttributeType AttributeType
AttributeType m_Attribute
SmartPointer< Self > Pointer
void SetAttribute(const std::string &s)
ImageType::IndexType IndexType
OutputImageType * GetOutput()
SmartPointer< const Self > ConstPointer
~ShapeKeepNObjectsLabelMapFilter()
Control indentation during Print() invocation.
ImageType::LabelObjectType LabelObjectType
void GenerateData() override
ShapeKeepNObjectsLabelMapFilter Self
ImageType::PixelType PixelType