18 #ifndef __itkLabelGeometryImageFilter_h
19 #define __itkLabelGeometryImageFilter_h
25 #include "itksys/hash_map.hxx"
28 #include "vnl/algo/vnl_symmetric_eigensystem.h"
29 #include "vnl/vnl_det.h"
30 #include "vnl/vnl_math.h"
31 #include "vcl_cmath.h"
78 template<
class TLabelImage,
class TIntensityImage = TLabelImage >
99 typedef typename TIntensityImage::SizeType
SizeType;
113 itkStaticConstMacro(ImageDimension,
unsigned int,
114 TLabelImage::ImageDimension);
170 const unsigned int imageDimension = itkGetStaticConstMacro(ImageDimension);
173 for (
unsigned int i = 0; i < imageDimension * 2; i += 2 )
179 m_BoundingBoxVolume = 0;
180 m_BoundingBoxSize.Fill(0);
181 m_PixelIndices.clear();
183 m_WeightedCentroid.Fill(0);
184 m_ZeroOrderMoment = 0;
185 m_FirstOrderRawMoments.Fill(0);
186 m_FirstOrderWeightedRawMoments.Fill(0);
187 m_Eigenvalues.resize(ImageDimension);
188 m_Eigenvalues.clear();
189 m_Eigenvectors.set_size(ImageDimension, ImageDimension);
190 m_Eigenvectors.fill(0);
191 m_AxesLength.Fill(0);
197 unsigned int numberOfVertices = (
unsigned int)vcl_pow( (
double)2, (int)ImageDimension );
198 m_OrientedBoundingBoxVertices.resize(numberOfVertices, emptyPoint);
199 m_OrientedBoundingBoxVolume = 0;
200 m_OrientedBoundingBoxSize.Fill(0);
201 m_OrientedLabelImage = LabelImageType::New();
202 m_OrientedIntensityImage = IntensityImageType::New();
203 m_OrientedBoundingBoxOrigin.Fill(0);
204 m_RotationMatrix.set_size(ImageDimension, ImageDimension);
205 m_RotationMatrix.fill(0.0);
207 m_SecondOrderRawMoments.set_size(ImageDimension, ImageDimension);
208 m_SecondOrderCentralMoments.set_size(ImageDimension, ImageDimension);
209 for (
unsigned int i = 0; i < ImageDimension; i++ )
211 for (
unsigned int j = 0; j < ImageDimension; j++ )
213 m_SecondOrderRawMoments(i, j) = 0;
214 m_SecondOrderCentralMoments(i, j) = 0;
251 typedef itksys::hash_map< LabelPixelType, LabelGeometry >
MapType;
252 typedef typename itksys::hash_map< LabelPixelType, LabelGeometry >::iterator
MapIterator;
253 typedef typename itksys::hash_map< LabelPixelType, LabelGeometry >::const_iterator
MapConstIterator;
256 itkGetMacro(CalculatePixelIndices,
bool);
257 itkBooleanMacro(CalculatePixelIndices);
258 void SetCalculatePixelIndices(
const bool value)
265 if ( value ==
false )
267 if ( ( this->m_CalculateOrientedBoundingBox ==
true )
268 || ( this->m_CalculateOrientedLabelRegions ==
true )
269 || ( this->m_CalculateOrientedIntensityRegions ==
true ) )
276 if ( this->m_CalculatePixelIndices != value )
278 this->m_CalculatePixelIndices = value;
283 itkGetMacro(CalculateOrientedBoundingBox,
bool);
284 itkBooleanMacro(CalculateOrientedBoundingBox);
285 void SetCalculateOrientedBoundingBox(
const bool value)
287 if ( this->m_CalculateOrientedBoundingBox != value )
289 this->m_CalculateOrientedBoundingBox = value;
297 this->SetCalculatePixelIndices(
true);
301 itkGetMacro(CalculateOrientedLabelRegions,
bool);
302 itkBooleanMacro(CalculateOrientedLabelRegions);
303 void SetCalculateOrientedLabelRegions(
const bool value)
305 if ( this->m_CalculateOrientedLabelRegions != value )
307 this->m_CalculateOrientedLabelRegions = value;
314 SetCalculateOrientedBoundingBox(
true);
319 itkGetMacro(CalculateOrientedIntensityRegions,
bool);
320 itkBooleanMacro(CalculateOrientedIntensityRegions);
321 void SetCalculateOrientedIntensityRegions(
const bool value)
323 if ( this->m_CalculateOrientedIntensityRegions != value )
325 this->m_CalculateOrientedIntensityRegions = value;
332 this->SetCalculateOrientedBoundingBox(
true);
338 void SetIntensityInput(
const TIntensityImage *input)
341 this->SetNthInput( 1, const_cast< TIntensityImage * >( input ) );
345 const TIntensityImage * GetIntensityInput()
const
354 return m_LabelGeometryMapper.find(label) != m_LabelGeometryMapper.end();
360 return m_LabelGeometryMapper.size();
365 return this->GetNumberOfObjects();
369 std::vector< LabelPixelType > GetLabels()
const
375 LabelIndicesType GetPixelIndices(LabelPixelType label)
const;
385 RealType GetIntegratedIntensity(LabelPixelType label)
const;
388 LabelPointType GetCentroid(LabelPixelType label)
const;
391 LabelPointType GetWeightedCentroid(LabelPixelType label)
const;
394 VectorType GetEigenvalues(LabelPixelType label)
const;
397 MatrixType GetEigenvectors(LabelPixelType label)
const;
400 AxesLengthType GetAxesLength(LabelPixelType label)
const;
404 RealType GetMinorAxisLength(LabelPixelType label)
const;
408 RealType GetMajorAxisLength(LabelPixelType label)
const;
411 RealType GetEccentricity(LabelPixelType label)
const;
415 RealType GetElongation(LabelPixelType label)
const;
418 RealType GetOrientation(LabelPixelType label)
const;
423 BoundingBoxType GetBoundingBox(LabelPixelType label)
const;
426 RealType GetBoundingBoxVolume(LabelPixelType label)
const;
429 LabelSizeType GetBoundingBoxSize(LabelPixelType label)
const;
437 BoundingBoxVerticesType GetOrientedBoundingBoxVertices(LabelPixelType label)
const;
440 RealType GetOrientedBoundingBoxVolume(LabelPixelType label)
const;
443 LabelPointType GetOrientedBoundingBoxSize(LabelPixelType label)
const;
446 LabelPointType GetOrientedBoundingBoxOrigin(LabelPixelType label)
const;
450 MatrixType GetRotationMatrix(LabelPixelType label)
const;
453 RegionType GetRegion(LabelPixelType label)
const;
456 TLabelImage * GetOrientedLabelImage(LabelPixelType label)
const;
460 TIntensityImage * GetOrientedIntensityImage(LabelPixelType label)
const;
462 #ifdef ITK_USE_CONCEPT_CHECKING
472 void PrintSelf(std::ostream & os,
Indent indent)
const;
479 void operator=(
const Self &);
481 bool CalculateOrientedBoundingBoxVertices(vnl_symmetric_eigensystem< double > eig, LabelGeometry & m_LabelGeometry);
495 template<
class TLabelImage,
class TIntensityImage >
497 vnl_symmetric_eigensystem< double > eig);
499 template<
class TLabelImage,
class TIntensityImage,
class TGenericImage >
502 vnl_symmetric_eigensystem< double > eig,
504 bool useLabelImage =
true);
507 #ifndef ITK_MANUAL_INSTANTIATION
508 #include "itkLabelGeometryImageFilter.hxx"