Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
itkFirstOrderStatisticsFeatureFunctor.h
Go to the documentation of this file.
1 #ifndef itkNeighborhoodFirstOrderStatistics_h
2 #define itkNeighborhoodFirstOrderStatistics_h
3 
4 #include "itkConstNeighborhoodIterator.h"
5 
6 namespace itk
7 {
8 
9 namespace Functor
10 {
11 
12 template< typename TNeighborhoodType, typename TPixelOutputType >
14 {
15  static const unsigned int OutputCount = 6;
16  typedef vnl_vector_fixed<TPixelOutputType, OutputCount> OutputVectorType;
17  typedef TNeighborhoodType NeighborhoodType;
19  {
21  };
22 
23  NeighborhoodFirstOrderStatistics(){std::cout << "NeighborhoodFirstOrderStatistics" << std::endl;}
24 
25  static const char * GetFeatureName(unsigned int f )
26  {
27  static const char * const FeatureNames[] = {"MEAN","VARIANCE","SKEWNESS", "KURTOSIS", "MIN", "MAX"};
28  return FeatureNames[f];
29  }
30 
31  inline OutputVectorType operator()(const NeighborhoodType & it) const
32  {
33  double mean = 0;
34  double sqmean = 0;
35  double min = 10000000;
36  double max = -10000000;
37 
38  for (int i = 0; i < it.Size(); ++i)
39  {
40  double value = it.GetPixel(i);
41  mean += value;
42  sqmean += (value * value);
43  max = (value > max) ? value : max;
44  min = (value < min) ? value : min;
45  }
46  mean /= it.Size();
47  sqmean /= it.Size();
48 
49  double variance = sqmean - mean * mean;
50 
51  double stdderivation = std::sqrt(variance);
52  double skewness = 0;
53  double kurtosis = 0;
54 
55  for (int i = 0; i < it.Size(); ++i)
56  {
57  double value = it.GetPixel(i);
58  double tmpskewness = (value - mean) / stdderivation;
59  skewness += tmpskewness * tmpskewness * tmpskewness;
60  kurtosis += (value - mean) * (value - mean) * (value - mean) * (value - mean);
61  }
62  skewness /= it.Size();
63  kurtosis /= it.Size();
64  kurtosis /= (variance * variance);
65 
66  if(skewness!=skewness){
67  skewness = 0;
68  }
69  if(kurtosis!=kurtosis){
70  kurtosis = 0;
71  }
72 
73  OutputVectorType output_vector;
74  output_vector[MEAN] = mean;
75  output_vector[VARIANCE] = variance;
76  output_vector[SKEWNESS] = skewness;
77  output_vector[KURTOSIS] = kurtosis;
78  output_vector[MIN] = min;
79  output_vector[MAX] = max;
80 
81  return output_vector;
82 
83  }
84 };
85 
86 }// end namespace functor
87 
88 } // end namespace itk
89 #endif
vnl_vector_fixed< TPixelOutputType, OutputCount > OutputVectorType
OutputVectorType operator()(const NeighborhoodType &it) const
static T max(T x, T y)
Definition: svm.cpp:70
static T min(T x, T y)
Definition: svm.cpp:67