18 #ifndef itkLabelGeometryImageFilter_h
19 #define itkLabelGeometryImageFilter_h
27 #include "vnl/algo/vnl_symmetric_eigensystem.h"
28 #include "vnl/vnl_det.h"
75 template <
typename TLabelImage,
typename TIntensityImage = TLabelImage>
99 using PixelType =
typename TIntensityImage::PixelType;
111 static constexpr
unsigned int ImageDimension = TLabelImage::ImageDimension;
162 const unsigned int imageDimension = Self::ImageDimension;
165 for (
unsigned int i = 0; i < imageDimension * 2; i += 2)
171 m_BoundingBoxVolume = 0;
172 m_BoundingBoxSize.Fill(0);
173 m_PixelIndices.clear();
175 m_WeightedCentroid.Fill(0);
176 m_ZeroOrderMoment = 0;
177 m_FirstOrderRawMoments.Fill(0);
178 m_FirstOrderWeightedRawMoments.Fill(0);
179 m_Eigenvalues.resize(ImageDimension);
180 m_Eigenvalues.clear();
181 m_Eigenvectors.set_size(ImageDimension, ImageDimension);
182 m_Eigenvectors.fill(0);
183 m_AxesLength.Fill(0);
189 unsigned int numberOfVertices = 1 << ImageDimension;
190 m_OrientedBoundingBoxVertices.resize(numberOfVertices, emptyPoint);
191 m_OrientedBoundingBoxVolume = 0;
192 m_OrientedBoundingBoxSize.Fill(0);
193 m_OrientedLabelImage = LabelImageType::New();
194 m_OrientedIntensityImage = IntensityImageType::New();
195 m_OrientedBoundingBoxOrigin.Fill(0);
196 m_RotationMatrix.set_size(ImageDimension, ImageDimension);
197 m_RotationMatrix.fill(0.0);
199 m_SecondOrderRawMoments.set_size(ImageDimension, ImageDimension);
200 m_SecondOrderCentralMoments.set_size(ImageDimension, ImageDimension);
201 for (
unsigned int i = 0; i < ImageDimension; i++)
203 for (
unsigned int j = 0; j < ImageDimension; j++)
205 m_SecondOrderRawMoments(i, j) = 0;
206 m_SecondOrderCentralMoments(i, j) = 0;
243 using MapType = std::map<LabelPixelType, LabelGeometry>;
244 using MapIterator =
typename std::map<LabelPixelType, LabelGeometry>::iterator;
248 itkGetMacro(CalculatePixelIndices,
bool);
249 itkBooleanMacro(CalculatePixelIndices);
260 if ((this->m_CalculateOrientedBoundingBox ==
true) || (this->m_CalculateOrientedLabelRegions ==
true) ||
261 (this->m_CalculateOrientedIntensityRegions ==
true))
268 if (this->m_CalculatePixelIndices != value)
270 this->m_CalculatePixelIndices = value;
275 itkGetMacro(CalculateOrientedBoundingBox,
bool);
276 itkBooleanMacro(CalculateOrientedBoundingBox);
280 if (this->m_CalculateOrientedBoundingBox != value)
282 this->m_CalculateOrientedBoundingBox = value;
290 this->SetCalculatePixelIndices(
true);
294 itkGetMacro(CalculateOrientedLabelRegions,
bool);
295 itkBooleanMacro(CalculateOrientedLabelRegions);
299 if (this->m_CalculateOrientedLabelRegions != value)
301 this->m_CalculateOrientedLabelRegions = value;
308 SetCalculateOrientedBoundingBox(
true);
313 itkGetMacro(CalculateOrientedIntensityRegions,
bool);
314 itkBooleanMacro(CalculateOrientedIntensityRegions);
318 if (this->m_CalculateOrientedIntensityRegions != value)
320 this->m_CalculateOrientedIntensityRegions = value;
327 this->SetCalculateOrientedBoundingBox(
true);
337 this->SetNthInput(1, const_cast<TIntensityImage *>(input));
341 const TIntensityImage *
352 return m_LabelGeometryMapper.find(label) != m_LabelGeometryMapper.end();
359 return m_LabelGeometryMapper.size();
365 return this->GetNumberOfObjects();
369 std::vector<LabelPixelType>
377 GetPixelIndices(LabelPixelType label)
const;
382 GetVolume(LabelPixelType label)
const;
389 GetIntegratedIntensity(LabelPixelType label)
const;
393 GetCentroid(LabelPixelType label)
const;
397 GetWeightedCentroid(LabelPixelType label)
const;
401 GetEigenvalues(LabelPixelType label)
const;
405 GetEigenvectors(LabelPixelType label)
const;
409 GetAxesLength(LabelPixelType label)
const;
414 GetMinorAxisLength(LabelPixelType label)
const;
419 GetMajorAxisLength(LabelPixelType label)
const;
423 GetEccentricity(LabelPixelType label)
const;
428 GetElongation(LabelPixelType label)
const;
432 GetOrientation(LabelPixelType label)
const;
438 GetBoundingBox(LabelPixelType label)
const;
442 GetBoundingBoxVolume(LabelPixelType label)
const;
446 GetBoundingBoxSize(LabelPixelType label)
const;
454 BoundingBoxVerticesType
455 GetOrientedBoundingBoxVertices(LabelPixelType label)
const;
459 GetOrientedBoundingBoxVolume(LabelPixelType label)
const;
463 GetOrientedBoundingBoxSize(LabelPixelType label)
const;
467 GetOrientedBoundingBoxOrigin(LabelPixelType label)
const;
472 GetRotationMatrix(LabelPixelType label)
const;
476 GetRegion(LabelPixelType label)
const;
480 GetOrientedLabelImage(LabelPixelType label)
const;
485 GetOrientedIntensityImage(LabelPixelType label)
const;
487 #ifdef ITK_USE_CONCEPT_CHECKING
497 PrintSelf(std::ostream & os,
Indent indent)
const override;
500 GenerateData()
override;
504 CalculateOrientedBoundingBoxVertices(vnl_symmetric_eigensystem<double> eig, LabelGeometry & m_LabelGeometry);
518 #ifndef ITK_MANUAL_INSTANTIATION
519 # include "itkLabelGeometryImageFilter.hxx"