ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkStatisticsLabelObject.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkStatisticsLabelObject_h
19 #define itkStatisticsLabelObject_h
20 
21 #include "itkShapeLabelObject.h"
22 #include "itkHistogram.h"
23 
24 namespace itk
25 {
40 template< typename TLabel, unsigned int VImageDimension >
41 class StatisticsLabelObject:public ShapeLabelObject< TLabel, VImageDimension >
42 {
43 public:
51 
53  itkNewMacro(Self);
54 
57 
59 
60  itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension);
61 
62  typedef typename Superclass::IndexType IndexType;
63 
65 
66  typedef TLabel LabelType;
67 
68  typedef typename Superclass::LineType LineType;
69 
71 
73 
75 
77 
79  itkStaticConstMacro(MINIMUM, AttributeType, 200);
80  itkStaticConstMacro(MAXIMUM, AttributeType, 201);
81  itkStaticConstMacro(MEAN, AttributeType, 202);
82  itkStaticConstMacro(SUM, AttributeType, 203);
83  itkStaticConstMacro(STANDARD_DEVIATION, AttributeType, 204);
84  itkStaticConstMacro(VARIANCE, AttributeType, 205);
85  itkStaticConstMacro(MEDIAN, AttributeType, 206);
86  itkStaticConstMacro(MAXIMUM_INDEX, AttributeType, 207);
87  itkStaticConstMacro(MINIMUM_INDEX, AttributeType, 208);
88  itkStaticConstMacro(CENTER_OF_GRAVITY, AttributeType, 209);
89 // itkStaticConstMacro(CENTRAL_MOMENTS, AttributeType, 210);
90  itkStaticConstMacro(WEIGHTED_PRINCIPAL_MOMENTS, AttributeType, 211);
91  itkStaticConstMacro(WEIGHTED_PRINCIPAL_AXES, AttributeType, 212);
92  itkStaticConstMacro(KURTOSIS, AttributeType, 213);
93  itkStaticConstMacro(SKEWNESS, AttributeType, 214);
94  itkStaticConstMacro(WEIGHTED_ELONGATION, AttributeType, 215);
95  itkStaticConstMacro(HISTOGRAM, AttributeType, 216);
96  itkStaticConstMacro(WEIGHTED_FLATNESS, AttributeType, 217);
97 
98  static AttributeType GetAttributeFromName(const std::string & s)
99  {
100  if ( s == "Minimum" )
101  {
102  return MINIMUM;
103  }
104  else if ( s == "Maximum" )
105  {
106  return MAXIMUM;
107  }
108  else if ( s == "Mean" )
109  {
110  return MEAN;
111  }
112  else if ( s == "Sum" )
113  {
114  return SUM;
115  }
116  else if ( s == "StandardDeviation" )
117  {
118  return STANDARD_DEVIATION;
119  }
120  else if ( s == "Variance" )
121  {
122  return VARIANCE;
123  }
124  else if ( s == "Median" )
125  {
126  return MEDIAN;
127  }
128  else if ( s == "MaximumIndex" )
129  {
130  return MAXIMUM_INDEX;
131  }
132  else if ( s == "MinimumIndex" )
133  {
134  return MINIMUM_INDEX;
135  }
136  else if ( s == "CenterOfGravity" )
137  {
138  return CENTER_OF_GRAVITY;
139  }
140  /*
141  else if( s == "CentralMoments" )
142  {
143  return CENTRAL_MOMENTS;
144  }
145  */
146  else if ( s == "WeightedPrincipalMoments" )
147  {
149  }
150  else if ( s == "WeightedPrincipalAxes" )
151  {
153  }
154  else if ( s == "Kurtosis" )
155  {
156  return KURTOSIS;
157  }
158  else if ( s == "Skewness" )
159  {
160  return SKEWNESS;
161  }
162  else if ( s == "WeightedElongation" )
163  {
164  return WEIGHTED_ELONGATION;
165  }
166  else if ( s == "Histogram" )
167  {
168  return HISTOGRAM;
169  }
170  else if ( s == "WeightedFlatness" )
171  {
172  return WEIGHTED_FLATNESS;
173  }
174  // can't recognize the name
176  }
177 
178  static std::string GetNameFromAttribute(const AttributeType & a)
179  {
180  switch ( a )
181  {
182  case MINIMUM:
183  return "Minimum";
184  break;
185  case MAXIMUM:
186  return "Maximum";
187  break;
188  case MEAN:
189  return "Mean";
190  break;
191  case SUM:
192  return "Sum";
193  break;
194  case STANDARD_DEVIATION:
195  return "StandardDeviation";
196  break;
197  case VARIANCE:
198  return "Variance";
199  break;
200  case MEDIAN:
201  return "Median";
202  break;
203  case MAXIMUM_INDEX:
204  return "MaximumIndex";
205  break;
206  case MINIMUM_INDEX:
207  return "MinimumIndex";
208  break;
209  case CENTER_OF_GRAVITY:
210  return "CenterOfGravity";
211  break;
212  /* case CENTRAL_MOMENTS:
213  return "CentralMoments";
214  break;*/
216  return "WeightedPrincipalMoments";
217  break;
219  return "WeightedPrincipalAxes";
220  break;
221  case KURTOSIS:
222  return "Kurtosis";
223  break;
224  case SKEWNESS:
225  return "Skewness";
226  break;
227  case WEIGHTED_ELONGATION:
228  return "WeightedElongation";
229  break;
230  case HISTOGRAM:
231  return "Histogram";
232  break;
233  case WEIGHTED_FLATNESS:
234  return "WeightedFlatness";
235  break;
236  }
237  // can't recognize the name
239  }
240 
242 
244 
245  template< typename TSourceLabelObject >
246  void CopyAttributesFrom( const TSourceLabelObject * src )
247  {
248  Superclass::template CopyAttributesFrom<TSourceLabelObject>(src);
249 
250  m_Minimum = src->GetMinimum();
251  m_Maximum = src->GetMaximum();
252  m_Mean = src->GetMean();
253  m_Sum = src->GetSum();
254  m_StandardDeviation = src->GetStandardDeviation();
255  m_Variance = src->GetVariance();
256  m_Median = src->GetMedian();
257  m_MaximumIndex = src->GetMaximumIndex();
258  m_MinimumIndex = src->GetMinimumIndex();
259  m_CenterOfGravity = src->GetCenterOfGravity();
260  // m_CentralMoments = src->GetCentralMoments();
261  m_WeightedPrincipalMoments = src->GetWeightedPrincipalMoments();
262  m_WeightedPrincipalAxes = src->GetWeightedPrincipalAxes();
263  m_Kurtosis = src->GetKurtosis();
264  m_Skewness = src->GetSkewness();
265  m_WeightedElongation = src->GetWeightedElongation();
266  m_Histogram = src->GetHistogram();
267  m_WeightedFlatness = src->GetWeightedFlatness();
268  }
269 
270  template< typename TSourceLabelObject >
271  void CopyAllFrom(const TSourceLabelObject *src)
272  {
273  itkAssertOrThrowMacro ( ( src != ITK_NULLPTR ), "Null Pointer" );
274  this->template CopyLinesFrom<TSourceLabelObject>( src );
275  this->template CopyAttributesFrom<TSourceLabelObject>( src );
276  }
277 
278  const double & GetMinimum() const
279  {
280  return m_Minimum;
281  }
282 
283  void SetMinimum(const double & v)
284  {
285  m_Minimum = v;
286  }
287 
288  const double & GetMaximum() const
289  {
290  return m_Maximum;
291  }
292 
293  void SetMaximum(const double & v)
294  {
295  m_Maximum = v;
296  }
297 
298  const double & GetMean() const
299  {
300  return m_Mean;
301  }
302 
303  void SetMean(const double & v)
304  {
305  m_Mean = v;
306  }
307 
308  const double & GetSum() const
309  {
310  return m_Sum;
311  }
312 
313  void SetSum(const double & v)
314  {
315  m_Sum = v;
316  }
317 
318  const double & GetStandardDeviation() const
319  {
320  return m_StandardDeviation;
321  }
322 
323  void SetStandardDeviation(const double & v)
324  {
326  }
327 
328  const double & GetVariance() const
329  {
330  return m_Variance;
331  }
332 
333  void SetVariance(const double & v)
334  {
335  m_Variance = v;
336  }
337 
338  const double & GetMedian() const
339  {
340  return m_Median;
341  }
342 
343  void SetMedian(const double & v)
344  {
345  m_Median = v;
346  }
347 
348  const IndexType & GetMaximumIndex() const
349  {
350  return m_MaximumIndex;
351  }
352 
353  void SetMaximumIndex(const IndexType & v)
354  {
355  m_MaximumIndex = v;
356  }
357 
358  const IndexType & GetMinimumIndex() const
359  {
360  return m_MinimumIndex;
361  }
362 
363  void SetMinimumIndex(const IndexType & v)
364  {
365  m_MinimumIndex = v;
366  }
367 
369  {
370  return m_CenterOfGravity;
371  }
372 
374  {
375  m_CenterOfGravity = v;
376  }
377 
378  /*
379  const MatrixType & GetCentralMoments() const
380  {
381  return m_CentralMoments;
382  }
383 
384  void SetCentralMoments( const MatrixType & v )
385  {
386  m_CentralMoments = v;
387  }*/
388 
390  {
392  }
393 
395  {
397  }
398 
400  {
402  }
403 
405  {
407  }
408 
409  const double & GetSkewness() const
410  {
411  return m_Skewness;
412  }
413 
414  void SetSkewness(const double & v)
415  {
416  m_Skewness = v;
417  }
418 
419  const double & GetKurtosis() const
420  {
421  return m_Kurtosis;
422  }
423 
424  void SetKurtosis(const double & v)
425  {
426  m_Kurtosis = v;
427  }
428 
429  const double & GetWeightedElongation() const
430  {
431  return m_WeightedElongation;
432  }
433 
434  void SetWeightedElongation(const double & v)
435  {
437  }
438 
439  const HistogramType * GetHistogram() const
440  {
441  return m_Histogram;
442  }
443 
445  {
446  m_Histogram = v;
447  }
448 
449  const double & GetWeightedFlatness() const
450  {
451  return m_WeightedFlatness;
452  }
453 
454  void SetWeightedFlatness(const double & v)
455  {
456  m_WeightedFlatness = v;
457  }
458 
459  // some helper methods - not really required, but really useful!
463 
468  {
469  typename AffineTransformType::MatrixType matrix;
470  typename AffineTransformType::OffsetType offset;
471  for ( unsigned int i = 0; i < ImageDimension; i++ )
472  {
473  offset[i] = m_CenterOfGravity[i];
474  for ( unsigned int j = 0; j < ImageDimension; j++ )
475  {
476  matrix[j][i] = m_WeightedPrincipalAxes[i][j]; // Note the transposition
477  }
478  }
480 
482 
483  result->SetMatrix(matrix);
484  result->SetOffset(offset);
485 
486  return result;
487  }
488 
494  {
495  typename AffineTransformType::MatrixType matrix;
496  typename AffineTransformType::OffsetType offset;
497  for ( unsigned int i = 0; i < ImageDimension; i++ )
498  {
499  offset[i] = m_CenterOfGravity[i];
500  for ( unsigned int j = 0; j < ImageDimension; j++ )
501  {
502  matrix[j][i] = m_WeightedPrincipalAxes[i][j]; // Note the transposition
503  }
504  }
506 
508  result->SetMatrix(matrix);
509  result->SetOffset(offset);
510 
512  result->GetInverse(inverse);
513 
514  return inverse;
515  }
516 
517 protected:
519  {
520  m_Minimum = 0;
521  m_Maximum = 0;
522  m_Mean = 0;
523  m_Sum = 0;
525  m_Variance = 0;
526  m_Median = 0;
527  m_MaximumIndex.Fill(0);
528  m_MinimumIndex.Fill(0);
530  // m_CentralMoments.Fill(0);
533  m_Kurtosis = 0;
534  m_Skewness = 0;
536  m_Histogram = ITK_NULLPTR;
537  m_WeightedFlatness = 0;
538  }
539 
540  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE
541  {
542  Superclass::PrintSelf(os, indent);
543 
544  os << indent << "Minimum: " << m_Minimum << std::endl;
545  os << indent << "Maximum: " << m_Maximum << std::endl;
546  os << indent << "Mean: " << m_Mean << std::endl;
547  os << indent << "Sum: " << m_Sum << std::endl;
548  os << indent << "StandardDeviation: " << m_StandardDeviation << std::endl;
549  os << indent << "Variance: " << m_Variance << std::endl;
550  os << indent << "Median: " << m_Median << std::endl;
551  os << indent << "Skewness: " << m_Skewness << std::endl;
552  os << indent << "Kurtosis: " << m_Kurtosis << std::endl;
553  os << indent << "WeightedElongation: " << m_WeightedElongation << std::endl;
554  os << indent << "WeightedFlatness: " << m_WeightedFlatness << std::endl;
555  os << indent << "MaximumIndex: " << m_MaximumIndex << std::endl;
556  os << indent << "MinimumIndex: " << m_MinimumIndex << std::endl;
557  os << indent << "CenterOfGravity: " << m_CenterOfGravity << std::endl;
558  // os << indent << "CentralMoments: " << std::endl << m_CentralMoments;
559  os << indent << "WeightedPrincipalMoments: " << m_WeightedPrincipalMoments << std::endl;
560  os << indent << "WeightedPrincipalAxes: " << std::endl << m_WeightedPrincipalAxes;
561  itkPrintSelfObjectMacro( Histogram );
562  }
563 
564 private:
565  ITK_DISALLOW_COPY_AND_ASSIGN(StatisticsLabelObject);
566 
567  double m_Minimum;
568  double m_Maximum;
569  double m_Mean;
570  double m_Sum;
572  double m_Variance;
573  double m_Median;
577  // MatrixType m_CentralMoments;
580  double m_Skewness;
581  double m_Kurtosis;
583 
585 
587 };
588 } // end namespace itk
589 
590 #endif
static const AttributeType MAXIMUM
void SetWeightedPrincipalMoments(const VectorType &v)
Superclass::MatrixType MatrixType
void SetStandardDeviation(const double &v)
Light weight base class for most itk classes.
static std::string GetNameFromAttribute(const AttributeType &a)
AffineTransformType::Pointer AffineTransformPointer
const PointType & GetCenterOfGravity() const
Superclass::AttributeType AttributeType
Superclass::LengthType LengthType
Superclass::LabelObjectType LabelObjectType
static Pointer New()
Point< double, VImageDimension > CentroidType
static const AttributeType MINIMUM_INDEX
AffineTransform< double, itkGetStaticConstMacro(ImageDimension) > AffineTransformType
static const AttributeType WEIGHTED_ELONGATION
static const AttributeType WEIGHTED_PRINCIPAL_MOMENTS
void CopyAttributesFrom(const TSourceLabelObject *src)
void SetMaximumIndex(const IndexType &v)
const HistogramType * GetHistogram() const
This class stores measurement vectors in the context of n-dimensional histogram.
Definition: itkHistogram.h:77
static const AttributeType MINIMUM
An image region represents a structured region of data.
void PrintSelf(std::ostream &os, Indent indent) const override
static const AttributeType MEAN
Vector< double, itkGetStaticConstMacro(ImageDimension) > VectorType
Superclass::CentroidType CentroidType
Implements a weak reference to an object.
Superclass::LabelObjectType LabelObjectType
Superclass::LengthType LengthType
Statistics::Histogram< double > HistogramType
static const AttributeType MEDIAN
void Fill(const ValueType &)
AffineTransformPointer GetPhysicalAxesToWeightedPrincipalAxesTransform(void) const
static const AttributeType WEIGHTED_FLATNESS
static AttributeType GetAttributeFromName(const std::string &s)
Point< double, itkGetStaticConstMacro(ImageDimension) > PointType
static const AttributeType SUM
void PrintSelf(std::ostream &os, Indent indent) const override
ShapeLabelObject< TLabel, VImageDimension > Superclass
Superclass::IndexType IndexType
A Label object to store the common attributes related to the statistics of the object.
void SetHistogram(const HistogramType *v)
const double & GetMedian() const
static const AttributeType MAXIMUM_INDEX
const double & GetKurtosis() const
Matrix< double, itkGetStaticConstMacro(ImageDimension), itkGetStaticConstMacro(ImageDimension) > MatrixType
const double & GetSkewness() const
Superclass::AttributeType AttributeType
Superclass::LineType LineType
void Fill(IndexValueType value)
Definition: itkIndex.h:293
const VectorType & GetWeightedPrincipalMoments() const
static AttributeType GetAttributeFromName(const std::string &s)
A Label object to store the common attributes related to the shape of the object. ...
ImageRegion< itkGetStaticConstMacro(ImageDimension) > RegionType
void SetMinimumIndex(const IndexType &v)
static const AttributeType CENTER_OF_GRAVITY
const MatrixType & GetWeightedPrincipalAxes() const
const double & GetStandardDeviation() const
WeakPointer< const Self > ConstWeakPointer
void SetWeightedElongation(const double &v)
static const unsigned int ImageDimension
Superclass::OffsetType OffsetType
SmartPointer< const Self > ConstPointer
The base class for the representation of an labeled binary object in an image.
static const AttributeType WEIGHTED_PRINCIPAL_AXES
HistogramType::ConstPointer m_Histogram
void SetWeightedPrincipalAxes(const MatrixType &v)
static const AttributeType KURTOSIS
const IndexType & GetMaximumIndex() const
const double & GetWeightedFlatness() const
static const AttributeType VARIANCE
const double & GetMaximum() const
Control indentation during Print() invocation.
Definition: itkIndent.h:49
void Fill(const T &value)
Definition: itkMatrix.h:191
AffineTransformPointer GetWeightedPrincipalAxesToPhysicalAxesTransform() const
Templated n-dimensional image to store labeled objects.
Definition: itkLabelMap.h:70
const double & GetMinimum() const
void SetWeightedFlatness(const double &v)
void SetCenterOfGravity(const PointType &v)
static std::string GetNameFromAttribute(const AttributeType &a)
static const AttributeType STANDARD_DEVIATION
const double & GetVariance() const
static const AttributeType SKEWNESS
static const AttributeType HISTOGRAM
void CopyAllFrom(const TSourceLabelObject *src)
const IndexType & GetMinimumIndex() const
const double & GetWeightedElongation() const