25 #include <itkLabelStatisticsImageFilter.h>
26 #include <itkNeighborhoodIterator.h>
29 #include <vtkSmartPointer.h>
30 #include <vtkImageMarchingCubes.h>
31 #include <vtkMassProperties.h>
35 #include <vnl/vnl_math.h>
37 template<
typename TPixel,
unsigned int VImageDimension>
41 typedef itk::Image<TPixel, VImageDimension>
ImageType;
42 typedef itk::Image<int, VImageDimension> MaskType;
43 typedef itk::LabelStatisticsImageFilter<ImageType, MaskType> FilterType;
49 labelStatisticsImageFilter->SetInput( itkImage );
50 labelStatisticsImageFilter->SetLabelInput(maskImage);
51 labelStatisticsImageFilter->Update();
53 double volume = labelStatisticsImageFilter->GetCount(1);
54 for (
int i = 0; i < (int)(VImageDimension); ++i)
56 volume *= itkImage->GetSpacing()[i];
59 featureList.push_back(std::make_pair(
"Volumetric Features Volume (pixel based)",volume));
62 template<
typename TPixel,
unsigned int VImageDimension>
66 typedef itk::Image<TPixel, VImageDimension>
ImageType;
68 typename ImageType::SizeType radius;
69 for (
int i=0; i < (int)VImageDimension; ++i)
71 itk::NeighborhoodIterator<ImageType> iterator(radius,mask, mask->GetRequestedRegion());
72 std::vector<PointType> borderPoints;
73 while(!iterator.IsAtEnd())
75 if (iterator.GetCenterPixel() == 0)
82 for (
int i = 0; i < (int)(iterator.Size()); ++i)
84 if (iterator.GetPixel(i) == 0)
92 auto centerIndex = iterator.GetIndex();
93 PointType centerPoint;
94 mask->TransformIndexToPhysicalPoint(centerIndex, centerPoint );
95 borderPoints.push_back(centerPoint);
100 double longestDiameter = 0;
101 unsigned long numberOfBorderPoints = borderPoints.size();
102 for (
int i = 0; i < (int)numberOfBorderPoints; ++i)
104 auto point = borderPoints[i];
105 for (
int j = i; j < (int)numberOfBorderPoints; ++j)
107 double newDiameter=point.EuclideanDistanceTo(borderPoints[j]);
108 if (newDiameter > longestDiameter)
109 longestDiameter = newDiameter;
113 featureList.push_back(std::make_pair(
"Volumetric Features Maximum 3D diameter",longestDiameter));
129 mesher->SetInputData(mask->GetVtkImageData());
130 stats->SetInputConnection(mesher->GetOutputPort());
133 double pi = vnl_math::pi;
135 double meshVolume = stats->GetVolume();
136 double meshSurf = stats->GetSurfaceArea();
137 double pixelVolume = featureList[0].second;
139 double compactness1 = pixelVolume / ( std::sqrt(pi) * std::pow(meshSurf, 2.0/3.0));
140 double compactness2 = 36*pi*pixelVolume*pixelVolume/meshSurf/meshSurf/meshSurf;
142 double sphericity=std::pow(pi,1/3.0) *std::pow(6*pixelVolume, 2.0/3.0) / meshSurf;
143 double surfaceToVolume = meshSurf / pixelVolume;
144 double sphericalDisproportion = meshSurf / 4 / pi / std::pow(3.0 / 4.0 / pi * pixelVolume, 2.0 / 3.0);
146 featureList.push_back(std::make_pair(
"Volumetric Features Volume (mesh based)",meshVolume));
147 featureList.push_back(std::make_pair(
"Volumetric Features Surface area",meshSurf));
148 featureList.push_back(std::make_pair(
"Volumetric Features Surface to volume ratio",surfaceToVolume));
149 featureList.push_back(std::make_pair(
"Volumetric Features Sphericity",sphericity));
150 featureList.push_back(std::make_pair(
"Volumetric Features Compactness 1",compactness1));
151 featureList.push_back(std::make_pair(
"Volumetric Features Compactness 2",compactness2));
152 featureList.push_back(std::make_pair(
"Volumetric Features Spherical disproportion",sphericalDisproportion));
160 featureList.push_back(
"Volumetric Features Compactness 1");
161 featureList.push_back(
"Volumetric Features Compactness 2");
162 featureList.push_back(
"Volumetric Features Sphericity");
163 featureList.push_back(
"Volumetric Features Surface to volume ratio");
164 featureList.push_back(
"Volumetric Features Surface area");
165 featureList.push_back(
"Volumetric Features Volume (mesh based)");
166 featureList.push_back(
"Volumetric Features Volume (pixel based)");
167 featureList.push_back(
"Volumetric Features Spherical disproportion");
168 featureList.push_back(
"Volumetric Features Maximum 3D diameter");
void CalculateVolumeStatistic(itk::Image< TPixel, VImageDimension > *itkImage, mitk::Image::Pointer mask, mitk::GIFVolumetricStatistics::FeatureListType &featureList)
itk::SmartPointer< Self > Pointer
GIFVolumetricStatistics()
std::vector< std::string > FeatureNameListType
itk::Image< unsigned char, 3 > ImageType
#define AccessByItk_1(mitkImage, itkImageTypeFunction, arg1)
std::vector< std::pair< std::string, double > > FeatureListType
void CalculateLargestDiameter(itk::Image< TPixel, VImageDimension > *mask, mitk::GIFVolumetricStatistics::FeatureListType &featureList)
virtual FeatureListType CalculateFeatures(const Image::Pointer &image, const Image::Pointer &feature)
Calculates the Cooccurence-Matrix based features for this class.
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
virtual FeatureNameListType GetFeatureNames()
Returns a list of the names of all features that are calculated from this class.
#define AccessByItk_2(mitkImage, itkImageTypeFunction, arg1, arg2)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.