18 #ifndef itkLabelGeometryImageFilter_h
19 #define itkLabelGeometryImageFilter_h
25 #include "itksys/hash_map.hxx"
27 #include "vnl/algo/vnl_symmetric_eigensystem.h"
28 #include "vnl/vnl_det.h"
76 template<
typename TLabelImage,
typename TIntensityImage = TLabelImage >
113 static constexpr
unsigned int ImageDimension = TLabelImage::ImageDimension;
126 Self::ImageDimension *2 >;
128 Self::ImageDimension *2 >;
139 Self::ImageDimension >;
167 const unsigned int imageDimension = Self::ImageDimension;
170 for (
unsigned int i = 0; i < imageDimension * 2; i += 2 )
176 m_BoundingBoxVolume = 0;
177 m_BoundingBoxSize.Fill(0);
178 m_PixelIndices.clear();
180 m_WeightedCentroid.Fill(0);
181 m_ZeroOrderMoment = 0;
182 m_FirstOrderRawMoments.Fill(0);
183 m_FirstOrderWeightedRawMoments.Fill(0);
184 m_Eigenvalues.resize(ImageDimension);
185 m_Eigenvalues.clear();
186 m_Eigenvectors.set_size(ImageDimension, ImageDimension);
187 m_Eigenvectors.fill(0);
188 m_AxesLength.Fill(0);
194 unsigned int numberOfVertices = 1 << ImageDimension;
195 m_OrientedBoundingBoxVertices.resize(numberOfVertices, emptyPoint);
196 m_OrientedBoundingBoxVolume = 0;
197 m_OrientedBoundingBoxSize.Fill(0);
198 m_OrientedLabelImage = LabelImageType::New();
199 m_OrientedIntensityImage = IntensityImageType::New();
200 m_OrientedBoundingBoxOrigin.Fill(0);
201 m_RotationMatrix.set_size(ImageDimension, ImageDimension);
202 m_RotationMatrix.fill(0.0);
204 m_SecondOrderRawMoments.set_size(ImageDimension, ImageDimension);
205 m_SecondOrderCentralMoments.set_size(ImageDimension, ImageDimension);
206 for (
unsigned int i = 0; i < ImageDimension; i++ )
208 for (
unsigned int j = 0; j < ImageDimension; j++ )
210 m_SecondOrderRawMoments(i, j) = 0;
211 m_SecondOrderCentralMoments(i, j) = 0;
248 using MapType = itksys::hash_map< LabelPixelType, LabelGeometry >;
249 using MapIterator =
typename itksys::hash_map< LabelPixelType, LabelGeometry >::iterator;
250 using MapConstIterator =
typename itksys::hash_map< LabelPixelType, LabelGeometry >::const_iterator;
253 itkGetMacro(CalculatePixelIndices,
bool);
254 itkBooleanMacro(CalculatePixelIndices);
262 if ( value ==
false )
264 if ( ( this->m_CalculateOrientedBoundingBox ==
true )
265 || ( this->m_CalculateOrientedLabelRegions ==
true )
266 || ( this->m_CalculateOrientedIntensityRegions ==
true ) )
273 if ( this->m_CalculatePixelIndices != value )
275 this->m_CalculatePixelIndices = value;
280 itkGetMacro(CalculateOrientedBoundingBox,
bool);
281 itkBooleanMacro(CalculateOrientedBoundingBox);
284 if ( this->m_CalculateOrientedBoundingBox != value )
286 this->m_CalculateOrientedBoundingBox = value;
294 this->SetCalculatePixelIndices(
true);
298 itkGetMacro(CalculateOrientedLabelRegions,
bool);
299 itkBooleanMacro(CalculateOrientedLabelRegions);
302 if ( this->m_CalculateOrientedLabelRegions != value )
304 this->m_CalculateOrientedLabelRegions = value;
311 SetCalculateOrientedBoundingBox(
true);
316 itkGetMacro(CalculateOrientedIntensityRegions,
bool);
317 itkBooleanMacro(CalculateOrientedIntensityRegions);
320 if ( this->m_CalculateOrientedIntensityRegions != value )
322 this->m_CalculateOrientedIntensityRegions = value;
329 this->SetCalculateOrientedBoundingBox(
true);
338 this->SetNthInput( 1, const_cast< TIntensityImage * >( input ) );
351 return m_LabelGeometryMapper.find(label) != m_LabelGeometryMapper.end();
357 return m_LabelGeometryMapper.size();
362 return this->GetNumberOfObjects();
372 LabelIndicesType GetPixelIndices(LabelPixelType label)
const;
382 RealType GetIntegratedIntensity(LabelPixelType label)
const;
385 LabelPointType GetCentroid(LabelPixelType label)
const;
388 LabelPointType GetWeightedCentroid(LabelPixelType label)
const;
391 VectorType GetEigenvalues(LabelPixelType label)
const;
394 MatrixType GetEigenvectors(LabelPixelType label)
const;
397 AxesLengthType GetAxesLength(LabelPixelType label)
const;
401 RealType GetMinorAxisLength(LabelPixelType label)
const;
405 RealType GetMajorAxisLength(LabelPixelType label)
const;
408 RealType GetEccentricity(LabelPixelType label)
const;
412 RealType GetElongation(LabelPixelType label)
const;
415 RealType GetOrientation(LabelPixelType label)
const;
420 BoundingBoxType GetBoundingBox(LabelPixelType label)
const;
423 RealType GetBoundingBoxVolume(LabelPixelType label)
const;
426 LabelSizeType GetBoundingBoxSize(LabelPixelType label)
const;
434 BoundingBoxVerticesType GetOrientedBoundingBoxVertices(LabelPixelType label)
const;
437 RealType GetOrientedBoundingBoxVolume(LabelPixelType label)
const;
440 LabelPointType GetOrientedBoundingBoxSize(LabelPixelType label)
const;
443 LabelPointType GetOrientedBoundingBoxOrigin(LabelPixelType label)
const;
447 MatrixType GetRotationMatrix(LabelPixelType label)
const;
450 RegionType GetRegion(LabelPixelType label)
const;
453 TLabelImage * GetOrientedLabelImage(LabelPixelType label)
const;
457 TIntensityImage * GetOrientedIntensityImage(LabelPixelType label)
const;
459 #ifdef ITK_USE_CONCEPT_CHECKING
469 void PrintSelf(std::ostream & os,
Indent indent)
const override;
471 void GenerateData()
override;
474 bool CalculateOrientedBoundingBoxVertices(vnl_symmetric_eigensystem< double > eig, LabelGeometry & m_LabelGeometry);
488 #ifndef ITK_MANUAL_INSTANTIATION
489 #include "itkLabelGeometryImageFilter.hxx"
MatrixType m_SecondOrderRawMoments
typename TLabelImage::RegionType LabelRegionType
bool HasLabel(LabelPixelType label) const
FixedArray< float, Self::ImageDimension > m_AxesLength
RealType m_OrientedBoundingBoxVolume
typename TLabelImage::PixelType LabelPixelType
typename itksys::hash_map< LabelPixelType, LabelGeometry >::const_iterator MapConstIterator
Light weight base class for most itk classes.
IntensityImageType::Pointer m_OrientedIntensityImage
MatrixType m_Eigenvectors
SizeValueType m_ZeroOrderMoment
Define numeric traits for std::vector.
void SetCalculateOrientedIntensityRegions(const bool value)
unsigned long SizeValueType
TIntensityImage IntensityImageType
std::vector< LabelPointType > BoundingBoxVerticesType
std::vector< double > VectorType
MapType m_LabelGeometryMapper
RealType m_FirstOrderCentralCrossMoment
MatrixType m_RotationMatrix
void SetCalculateOrientedBoundingBox(const bool value)
typename TIntensityImage::RegionType RegionType
LabelPointType m_OrientedBoundingBoxOrigin
typename TIntensityImage::IndexType IndexType
IndexArrayType m_FirstOrderRawMoments
Geometry stored per label.
typename TLabelImage::IndexType LabelIndexType
std::vector< LabelPixelType > LabelsType
void SetCalculateOrientedLabelRegions(const bool value)
typename TIntensityImage::Pointer InputImagePointer
LabelIndicesType m_PixelIndices
Decorates any "simple" data type (data types without smart pointers) with a DataObject API...
IndexArrayType m_FirstOrderWeightedRawMoments
ImageBaseType::SizeType SizeType
void SetCalculatePixelIndices(const bool value)
typename NumericTraits< PixelType >::RealType RealType
vnl_matrix< double > MatrixType
TLabelImage LabelImageType
ImageBaseType::IndexType IndexType
SizeValueType GetNumberOfLabels() const
typename TLabelImage::SizeType LabelSizeType
bool m_CalculateOrientedBoundingBox
signed long IndexValueType
BoundingBoxVerticesType m_OrientedBoundingBoxVertices
std::vector< LabelPixelType > GetLabels() const
LabelGeometry m_LabelGeometry
RealType m_BoundingBoxVolume
bool m_CalculatePixelIndices
Given a label map and an optional intensity image, compute geometric features.
DataObject * GetInput(const DataObjectIdentifierType &key)
Return an input.
SizeValueType GetNumberOfObjects() const
bool m_CalculateOrientedLabelRegions
void SetIntensityInput(const TIntensityImage *input)
typename TLabelImage::PointType LabelPointType
LabelPointType m_OrientedBoundingBoxSize
std::vector< LabelIndexType > LabelIndicesType
LabelImageType::Pointer m_OrientedLabelImage
Base class for filters that take an image as input and produce an image as output.
typename TIntensityImage::SizeType SizeType
typename TIntensityImage::PixelType PixelType
const TIntensityImage * GetIntensityInput() const
typename itksys::hash_map< LabelPixelType, LabelGeometry >::iterator MapIterator
Control indentation during Print() invocation.
MatrixType m_SecondOrderCentralMoments
ImageBaseType::PointType PointType
BoundingBoxType m_BoundingBox
itksys::hash_map< LabelPixelType, LabelGeometry > MapType
SizeValueType m_FirstOrderRawCrossMoment
ImageBaseType::RegionType RegionType
SmartPointer< Self > Pointer
ImageBaseType::SpacingType VectorType
typename TLabelImage::Pointer LabelImagePointer
#define itkConceptMacro(name, concept)
Base class for all data objects in ITK.
bool m_CalculateOrientedIntensityRegions
LabelPointType m_Centroid
LabelSizeType m_BoundingBoxSize
LabelPointType m_WeightedCentroid