Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkExtendedLabelStatisticsImageFilter.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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 #ifndef __mitkExtendedLabelStatisticsImageFilter
17 #define __mitkExtendedLabelStatisticsImageFilter
18 
19 #include "itkLabelStatisticsImageFilter.h"
20 
21 namespace itk
22 {
33  template< class TInputImage, class TLabelImage >
34  class ExtendedLabelStatisticsImageFilter : public LabelStatisticsImageFilter< TInputImage, TLabelImage >
35  {
36  public:
37 
39  typedef LabelStatisticsImageFilter < TInputImage, TLabelImage > Superclass;
42  typedef typename Superclass::LabelPixelType LabelPixelType;
43  typedef typename Superclass::RealType RealType;
44  typedef typename Superclass::PixelType PixelType;
45  typedef typename Superclass::MapIterator MapIterator;
47  typedef typename Superclass::RegionType RegionType;
48  typedef itk::Statistics::Histogram<double> HistogramType;
49 
50  itkFactorylessNewMacro( Self );
51  itkCloneMacro( Self );
52  itkTypeMacro(ExtendedLabelStatisticsImageFilter, LabelStatisticsImageFilter);
53 
54 
60  {
61  public:
62 
63  // default constructor
65  {
66  // initialized to the default values
67  m_Count = NumericTraits< IdentifierType >::ZeroValue();
68  m_PositivePixelCount = NumericTraits< IdentifierType >::ZeroValue();
69  m_Sum = NumericTraits< RealType >::ZeroValue();
70  m_SumOfPositivePixels = NumericTraits< RealType >::ZeroValue();
71 
72  m_SumOfSquares = NumericTraits< RealType >::ZeroValue();
73  m_SumOfCubes = NumericTraits< RealType >::ZeroValue();
74  m_SumOfQuadruples = NumericTraits< RealType >::ZeroValue();
75 
76  // Set such that the first pixel encountered can be compared
78  m_Maximum = NumericTraits< RealType >::NonpositiveMin();
79 
80  // Default these to zero
81  m_Mean = NumericTraits< RealType >::ZeroValue();
82  m_Sigma = NumericTraits< RealType >::ZeroValue();
83  m_Variance = NumericTraits< RealType >::ZeroValue();
84  m_MPP = NumericTraits< RealType >::ZeroValue();
85  m_Median = NumericTraits< RealType >::ZeroValue();
86  m_Uniformity = NumericTraits< RealType >::ZeroValue();
87  m_UPP = NumericTraits< RealType >::ZeroValue();
88  m_Entropy = NumericTraits< RealType >::ZeroValue();
89  m_Skewness = NumericTraits< RealType >::ZeroValue();
90  m_Kurtosis = NumericTraits< RealType >::ZeroValue();
91 
92  unsigned int imageDimension = itkGetStaticConstMacro(ImageDimension);
93  m_BoundingBox.resize(imageDimension * 2);
94  for ( unsigned int i = 0; i < imageDimension * 2; i += 2 )
95  {
97  m_BoundingBox[i + 1] = NumericTraits< IndexValueType >::NonpositiveMin();
98  }
99  m_Histogram = ITK_NULLPTR;
100  }
101 
102  // constructor with histogram enabled
103  LabelStatistics(int size, RealType lowerBound, RealType upperBound)
104  {
105  // initialized to the default values
106  m_Count = NumericTraits< IdentifierType >::ZeroValue();
107  m_PositivePixelCount = NumericTraits< IdentifierType >::ZeroValue();
108  m_Sum = NumericTraits< RealType >::ZeroValue();
109  m_SumOfPositivePixels = NumericTraits< RealType >::ZeroValue();
110 
111  m_SumOfSquares = NumericTraits< RealType >::ZeroValue();
112  m_SumOfCubes = NumericTraits< RealType >::ZeroValue();
113  m_SumOfQuadruples = NumericTraits< RealType >::ZeroValue();
114 
115  // Set such that the first pixel encountered can be compared
117  m_Maximum = NumericTraits< RealType >::NonpositiveMin();
118 
119  // Default these to zero
120  m_Mean = NumericTraits< RealType >::ZeroValue();
121  m_Sigma = NumericTraits< RealType >::ZeroValue();
122  m_Variance = NumericTraits< RealType >::ZeroValue();
123  m_MPP = NumericTraits< RealType >::ZeroValue();
124  m_Median = NumericTraits< RealType >::ZeroValue();
125  m_Uniformity = NumericTraits< RealType >::ZeroValue();
126  m_UPP = NumericTraits< RealType >::ZeroValue();
127  m_Entropy = NumericTraits< RealType >::ZeroValue();
128  m_Skewness = NumericTraits< RealType >::ZeroValue();
129  m_Kurtosis = NumericTraits< RealType >::ZeroValue();
130 
131 
132  unsigned int imageDimension = itkGetStaticConstMacro(ImageDimension);
133  m_BoundingBox.resize(imageDimension * 2);
134  for ( unsigned int i = 0; i < imageDimension * 2; i += 2 )
135  {
137  m_BoundingBox[i + 1] = NumericTraits< IndexValueType >::NonpositiveMin();
138  }
139 
140  // Histogram
142  typename HistogramType::SizeType hsize;
143  typename HistogramType::MeasurementVectorType lb;
144  typename HistogramType::MeasurementVectorType ub;
145  hsize.SetSize(1);
146  lb.SetSize(1);
147  ub.SetSize(1);
148  m_Histogram->SetMeasurementVectorSize(1);
149  hsize[0] = size;
150  lb[0] = lowerBound;
151  ub[0] = upperBound;
152  m_Histogram->Initialize(hsize, lb, ub);
153  }
154 
155  // need copy constructor because of smart pointer to histogram
157  {
158  m_Count = l.m_Count;
159  m_Minimum = l.m_Minimum;
160  m_Maximum = l.m_Maximum;
161  m_Mean = l.m_Mean;
162  m_Sum = l.m_Sum;
164  m_Sigma = l.m_Sigma;
166  m_MPP = l.m_MPP;
167  m_Median = l.m_Median;
169  m_UPP = l.m_UPP;
170  m_Entropy = l.m_Entropy;
179  }
180 
181  // added for completeness
183  {
184  if(this != &l)
185  {
186  m_Count = l.m_Count;
187  m_Minimum = l.m_Minimum;
188  m_Maximum = l.m_Maximum;
189  m_Mean = l.m_Mean;
190  m_Sum = l.m_Sum;
192  m_Sigma = l.m_Sigma;
194  m_MPP = l.m_MPP;
195  m_Median = l.m_Median;
197  m_UPP = l.m_UPP;
198  m_Entropy = l.m_Entropy;
207  }
208  return *this;
209  }
210 
211  IdentifierType m_Count;
212  RealType m_Minimum;
213  RealType m_Maximum;
214  RealType m_Mean;
215  RealType m_Sum;
216  RealType m_SumOfSquares;
217  RealType m_Sigma;
218  RealType m_Variance;
219  RealType m_MPP;
220  RealType m_Median;
221  RealType m_Uniformity;
222  RealType m_UPP;
223  RealType m_Entropy;
224  RealType m_Skewness;
225  RealType m_Kurtosis;
226  IdentifierType m_PositivePixelCount;
228  RealType m_SumOfCubes;
232  };
233 
235  typedef itksys::hash_map< LabelPixelType, LabelStatistics > MapType;
236  typedef typename itksys::hash_map< LabelPixelType, LabelStatistics >::const_iterator StatisticsMapConstIterator;
237  typedef typename itksys::hash_map< LabelPixelType, LabelStatistics >::iterator StatisticsMapIterator;
238  typedef IdentifierType MapSizeType;
239 
241  typedef std::vector<LabelPixelType> ValidLabelValuesContainerType;
242 
244  RealType GetMinimum(LabelPixelType label) const;
245 
247  RealType GetMaximum(LabelPixelType label) const;
248 
250  RealType GetMean(LabelPixelType label) const;
251 
253  RealType GetSigma(LabelPixelType label) const;
254 
256  RealType GetVariance(LabelPixelType label) const;
257 
259  BoundingBoxType GetBoundingBox(LabelPixelType label) const;
260 
262  RegionType GetRegion(LabelPixelType label) const;
263 
265  RealType GetSum(LabelPixelType label) const;
266 
268  MapSizeType GetCount(LabelPixelType label) const;
269 
271  HistogramType::Pointer GetHistogram(LabelPixelType label) const;
272 
273  /*getter method for the new statistics*/
274  RealType GetSkewness(LabelPixelType label) const;
275  RealType GetKurtosis(LabelPixelType label) const;
276  RealType GetUniformity( LabelPixelType label) const;
277  RealType GetMedian( LabelPixelType label) const;
278  RealType GetEntropy( LabelPixelType label) const;
279  RealType GetMPP( LabelPixelType label) const;
280  RealType GetUPP( LabelPixelType label) const;
281 
282  bool GetMaskingNonEmpty() const;
283 
284  std::list<int> GetRelevantLabels() const;
285 
286 
288  void SetHistogramParameters(const int numBins, RealType lowerBound,
289  RealType upperBound);
290 
292  void SetHistogramParametersForLabels(std::map<LabelPixelType, unsigned int> numBins, std::map<LabelPixelType, PixelType> lowerBound,
293  std::map<LabelPixelType, PixelType> upperBound);
294 
295  protected:
297  m_GlobalHistogramParametersSet(false),
298  m_LabelHistogramParametersSet(false),
299  m_PreferGlobalHistogramParameters(false)
300  {
301  m_NumBins.set_size(1);
302  }
303 
305 
307 
310 
312  void ThreadedGenerateData(const typename TInputImage::RegionType &
313  outputRegionForThread,
314  ThreadIdType threadId);
315 
318  bool HasLabel(LabelPixelType label) const
319  {
320  return m_LabelStatistics.find(label) != m_LabelStatistics.end();
321  }
322 
323  private:
324  std::vector< MapType > m_LabelStatisticsPerThread;
325  MapType m_LabelStatistics;
326  ValidLabelValuesContainerType m_ValidLabelValues;
327 
328  bool m_GlobalHistogramParametersSet;
329 
330  typename HistogramType::SizeType m_NumBins;
331 
332  RealType m_LowerBound;
333  RealType m_UpperBound;
334 
335  bool m_MaskNonEmpty;
336 
337  bool m_LabelHistogramParametersSet;
338  std::map<LabelPixelType, PixelType> m_LabelMin, m_LabelMax;
339  std::map<LabelPixelType, unsigned int> m_LabelNBins;
340  bool m_PreferGlobalHistogramParameters;
341 
342  }; // end of class
343 
344 } // end namespace itk
345 
346 #ifndef ITK_MANUAL_INSTANTIATION
347 #include "mitkExtendedLabelStatisticsImageFilter.hxx"
348 #endif
349 
350 #endif
RealType GetMaximum(LabelPixelType label) const
std::list< int > GetRelevantLabels() const
RealType GetUniformity(LabelPixelType label) const
itk::SmartPointer< Self > Pointer
RealType GetMPP(LabelPixelType label) const
RealType GetUPP(LabelPixelType label) const
RealType GetVariance(LabelPixelType label) const
Extension of the itkLabelStatisticsImageFilter that also calculates the Skewness,Kurtosis,Entropy,Uniformity.
RealType GetKurtosis(LabelPixelType label) const
void SetHistogramParametersForLabels(std::map< LabelPixelType, unsigned int > numBins, std::map< LabelPixelType, PixelType > lowerBound, std::map< LabelPixelType, PixelType > upperBound)
RealType GetSigma(LabelPixelType label) const
RegionType GetRegion(LabelPixelType label) const
RealType GetMedian(LabelPixelType label) const
HistogramType::Pointer GetHistogram(LabelPixelType label) const
void SetHistogramParameters(const int numBins, RealType lowerBound, RealType upperBound)
void ThreadedGenerateData(const typename TInputImage::RegionType &outputRegionForThread, ThreadIdType threadId)
RealType GetMinimum(LabelPixelType label) const
itk::BoundingBox< unsigned long, 3, mitk::ScalarType > BoundingBoxType
itksys::hash_map< LabelPixelType, LabelStatistics >::iterator StatisticsMapIterator
static T max(T x, T y)
Definition: svm.cpp:70
RealType GetSum(LabelPixelType label) const
RealType GetEntropy(LabelPixelType label) const
RealType GetMean(LabelPixelType label) const
BoundingBoxType GetBoundingBox(LabelPixelType label) const
itksys::hash_map< LabelPixelType, LabelStatistics >::const_iterator StatisticsMapConstIterator
RealType GetSkewness(LabelPixelType label) const
unsigned short PixelType
LabelStatistics(int size, RealType lowerBound, RealType upperBound)
MapSizeType GetCount(LabelPixelType label) const
itksys::hash_map< LabelPixelType, LabelStatistics > MapType
LabelStatisticsImageFilter< TInputImage, TLabelImage > Superclass
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.