Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
itkFirstOrderStatisticsFeatureFunctor.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef itkFirstOrderStatisticsFeatureFunctor_h
14 #define itkFirstOrderStatisticsFeatureFunctor_h
15 
16 #include <itkConstNeighborhoodIterator.h>
17 
18 namespace itk
19 {
20 
21 namespace Functor
22 {
23 
30 template< typename TNeighborhoodType, typename TPixelOutputType >
32 {
33  static const unsigned int OutputCount = 6;
34  typedef vnl_vector_fixed<TPixelOutputType, OutputCount> OutputVectorType;
35  typedef TNeighborhoodType NeighborhoodType;
37  {
39  };
40 
41  NeighborhoodFirstOrderStatistics(){std::cout << "NeighborhoodFirstOrderStatistics" << std::endl;}
42 
43  static const char * GetFeatureName(unsigned int f )
44  {
45  static const char * const FeatureNames[] = {"MEAN","VARIANCE","SKEWNESS", "KURTOSIS", "MIN", "MAX"};
46  return FeatureNames[f];
47  }
48 
49  inline OutputVectorType operator()(const NeighborhoodType & it) const
50  {
51  double mean = 0;
52  double sqmean = 0;
53  double min = 10000000;
54  double max = -10000000;
55 
56  for (unsigned int i = 0; i < it.Size(); ++i)
57  {
58  double value = it.GetPixel(i);
59  mean += value;
60  sqmean += (value * value);
61  max = (value > max) ? value : max;
62  min = (value < min) ? value : min;
63  }
64  mean /= it.Size();
65  sqmean /= it.Size();
66 
67  double variance = sqmean - mean * mean;
68 
69  double stdderivation = std::sqrt(variance);
70  double skewness = 0;
71  double kurtosis = 0;
72 
73  for (unsigned int i = 0; i < it.Size(); ++i)
74  {
75  double value = it.GetPixel(i);
76  double tmpskewness = (value - mean) / stdderivation;
77  skewness += tmpskewness * tmpskewness * tmpskewness;
78  kurtosis += (value - mean) * (value - mean) * (value - mean) * (value - mean);
79  }
80  skewness /= it.Size();
81  kurtosis /= it.Size();
82  kurtosis /= (variance * variance);
83 
84  if(skewness!=skewness){
85  skewness = 0;
86  }
87  if(kurtosis!=kurtosis){
88  kurtosis = 0;
89  }
90 
91  OutputVectorType output_vector;
92  output_vector[MEAN] = mean;
93  output_vector[VARIANCE] = variance;
94  output_vector[SKEWNESS] = skewness;
95  output_vector[KURTOSIS] = kurtosis;
96  output_vector[MIN] = min;
97  output_vector[MAX] = max;
98 
99  return output_vector;
100 
101  }
102 };
103 
104 }// end namespace functor
105 
106 } // end namespace itk
107 #endif
Functor that computes first-order statistics (mean, variance, skewness, kurtosis, min,...
OutputVectorType operator()(const NeighborhoodType &it) const
vnl_vector_fixed< TPixelOutputType, OutputCount > OutputVectorType