ITK  4.6.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  virtual void CopyAttributesFrom(const LabelObjectType *lo)
246  {
248 
249  // copy the data of the current type if possible
250  const Self *src = dynamic_cast< const Self * >( lo );
251  if ( src == ITK_NULLPTR )
252  {
253  return;
254  }
255  m_Minimum = src->m_Minimum;
256  m_Maximum = src->m_Maximum;
257  m_Mean = src->m_Mean;
258  m_Sum = src->m_Sum;
259  m_StandardDeviation = src->m_StandardDeviation;
260  m_Variance = src->m_Variance;
261  m_Median = src->m_Median;
262  m_MaximumIndex = src->m_MaximumIndex;
263  m_MinimumIndex = src->m_MinimumIndex;
264  m_CenterOfGravity = src->m_CenterOfGravity;
265  // m_CentralMoments = src->m_CentralMoments;
266  m_WeightedPrincipalMoments = src->m_WeightedPrincipalMoments;
267  m_WeightedPrincipalAxes = src->m_WeightedPrincipalAxes;
268  m_Kurtosis = src->m_Kurtosis;
269  m_Skewness = src->m_Skewness;
270  m_WeightedElongation = src->m_WeightedElongation;
271  m_Histogram = src->m_Histogram;
272  m_WeightedFlatness = src->m_WeightedFlatness;
273  }
274 
275  const double & GetMinimum() const
276  {
277  return m_Minimum;
278  }
279 
280  void SetMinimum(const double & v)
281  {
282  m_Minimum = v;
283  }
284 
285  const double & GetMaximum() const
286  {
287  return m_Maximum;
288  }
289 
290  void SetMaximum(const double & v)
291  {
292  m_Maximum = v;
293  }
294 
295  const double & GetMean() const
296  {
297  return m_Mean;
298  }
299 
300  void SetMean(const double & v)
301  {
302  m_Mean = v;
303  }
304 
305  const double & GetSum() const
306  {
307  return m_Sum;
308  }
309 
310  void SetSum(const double & v)
311  {
312  m_Sum = v;
313  }
314 
315  const double & GetStandardDeviation() const
316  {
317  return m_StandardDeviation;
318  }
319 
320  void SetStandardDeviation(const double & v)
321  {
323  }
324 
325  const double & GetVariance() const
326  {
327  return m_Variance;
328  }
329 
330  void SetVariance(const double & v)
331  {
332  m_Variance = v;
333  }
334 
335  const double & GetMedian() const
336  {
337  return m_Median;
338  }
339 
340  void SetMedian(const double & v)
341  {
342  m_Median = v;
343  }
344 
345  const IndexType & GetMaximumIndex() const
346  {
347  return m_MaximumIndex;
348  }
349 
350  void SetMaximumIndex(const IndexType & v)
351  {
352  m_MaximumIndex = v;
353  }
354 
355  const IndexType & GetMinimumIndex() const
356  {
357  return m_MinimumIndex;
358  }
359 
360  void SetMinimumIndex(const IndexType & v)
361  {
362  m_MinimumIndex = v;
363  }
364 
366  {
367  return m_CenterOfGravity;
368  }
369 
371  {
372  m_CenterOfGravity = v;
373  }
374 
375  /*
376  const MatrixType & GetCentralMoments() const
377  {
378  return m_CentralMoments;
379  }
380 
381  void SetCentralMoments( const MatrixType & v )
382  {
383  m_CentralMoments = v;
384  }*/
385 
387  {
389  }
390 
392  {
394  }
395 
397  {
399  }
400 
402  {
404  }
405 
406  const double & GetSkewness() const
407  {
408  return m_Skewness;
409  }
410 
411  void SetSkewness(const double & v)
412  {
413  m_Skewness = v;
414  }
415 
416  const double & GetKurtosis() const
417  {
418  return m_Kurtosis;
419  }
420 
421  void SetKurtosis(const double & v)
422  {
423  m_Kurtosis = v;
424  }
425 
426  const double & GetWeightedElongation() const
427  {
428  return m_WeightedElongation;
429  }
430 
431  void SetWeightedElongation(const double & v)
432  {
434  }
435 
436  const HistogramType * GetHistogram() const
437  {
438  return m_Histogram;
439  }
440 
442  {
443  m_Histogram = v;
444  }
445 
446  const double & GetWeightedFlatness() const
447  {
448  return m_WeightedFlatness;
449  }
450 
451  void SetWeightedFlatness(const double & v)
452  {
453  m_WeightedFlatness = v;
454  }
455 
456  // some helper methods - not really required, but really useful!
460 
465  {
466  typename AffineTransformType::MatrixType matrix;
467  typename AffineTransformType::OffsetType offset;
468  for ( unsigned int i = 0; i < ImageDimension; i++ )
469  {
470  offset[i] = m_CenterOfGravity[i];
471  for ( unsigned int j = 0; j < ImageDimension; j++ )
472  {
473  matrix[j][i] = m_WeightedPrincipalAxes[i][j]; // Note the transposition
474  }
475  }
477 
479 
480  result->SetMatrix(matrix);
481  result->SetOffset(offset);
482 
483  return result;
484  }
485 
491  {
492  typename AffineTransformType::MatrixType matrix;
493  typename AffineTransformType::OffsetType offset;
494  for ( unsigned int i = 0; i < ImageDimension; i++ )
495  {
496  offset[i] = m_CenterOfGravity[i];
497  for ( unsigned int j = 0; j < ImageDimension; j++ )
498  {
499  matrix[j][i] = m_WeightedPrincipalAxes[i][j]; // Note the transposition
500  }
501  }
503 
505  result->SetMatrix(matrix);
506  result->SetOffset(offset);
507 
509  result->GetInverse(inverse);
510 
511  return inverse;
512  }
513 
514 protected:
516  {
517  m_Minimum = 0;
518  m_Maximum = 0;
519  m_Mean = 0;
520  m_Sum = 0;
522  m_Variance = 0;
523  m_Median = 0;
524  m_MaximumIndex.Fill(0);
525  m_MinimumIndex.Fill(0);
527  // m_CentralMoments.Fill(0);
530  m_Kurtosis = 0;
531  m_Skewness = 0;
533  m_Histogram = ITK_NULLPTR;
534  m_WeightedFlatness = 0;
535  }
536 
537  void PrintSelf(std::ostream & os, Indent indent) const
538  {
539  Superclass::PrintSelf(os, indent);
540 
541  os << indent << "Minimum: " << m_Minimum << std::endl;
542  os << indent << "Maximum: " << m_Maximum << std::endl;
543  os << indent << "Mean: " << m_Mean << std::endl;
544  os << indent << "Sum: " << m_Sum << std::endl;
545  os << indent << "StandardDeviation: " << m_StandardDeviation << std::endl;
546  os << indent << "Variance: " << m_Variance << std::endl;
547  os << indent << "Median: " << m_Median << std::endl;
548  os << indent << "Skewness: " << m_Skewness << std::endl;
549  os << indent << "Kurtosis: " << m_Kurtosis << std::endl;
550  os << indent << "WeightedElongation: " << m_WeightedElongation << std::endl;
551  os << indent << "WeightedFlatness: " << m_WeightedFlatness << std::endl;
552  os << indent << "MaximumIndex: " << m_MaximumIndex << std::endl;
553  os << indent << "MinimumIndex: " << m_MinimumIndex << std::endl;
554  os << indent << "CenterOfGravity: " << m_CenterOfGravity << std::endl;
555  // os << indent << "CentralMoments: " << std::endl << m_CentralMoments;
556  os << indent << "WeightedPrincipalMoments: " << m_WeightedPrincipalMoments << std::endl;
557  os << indent << "WeightedPrincipalAxes: " << std::endl << m_WeightedPrincipalAxes;
558  itkPrintSelfObjectMacro( Histogram );
559  }
560 
561 private:
562  StatisticsLabelObject(const Self &); //purposely not implemented
563  void operator=(const Self &); //purposely not implemented
564 
565  double m_Minimum;
566  double m_Maximum;
567  double m_Mean;
568  double m_Sum;
570  double m_Variance;
571  double m_Median;
575  // MatrixType m_CentralMoments;
578  double m_Skewness;
579  double m_Kurtosis;
581 
583 
585 };
586 } // end namespace itk
587 
588 #endif
static const AttributeType MAXIMUM
void SetWeightedPrincipalMoments(const VectorType &v)
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
Point< double, VImageDimension > CentroidType
static const AttributeType MINIMUM_INDEX
void PrintSelf(std::ostream &os, Indent indent) const
AffineTransform< double, itkGetStaticConstMacro(ImageDimension) > AffineTransformType
static const AttributeType WEIGHTED_ELONGATION
static const AttributeType WEIGHTED_PRINCIPAL_MOMENTS
void SetMaximumIndex(const IndexType &v)
const HistogramType * GetHistogram() const
void operator=(const Self &)
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.
static const AttributeType MEAN
Vector< double, itkGetStaticConstMacro(ImageDimension) > VectorType
static Pointer New()
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
virtual void CopyAttributesFrom(const LabelObjectType *lo)
static const AttributeType WEIGHTED_FLATNESS
static AttributeType GetAttributeFromName(const std::string &s)
Point< double, itkGetStaticConstMacro(ImageDimension) > PointType
static const AttributeType SUM
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:292
const VectorType & GetWeightedPrincipalMoments() const
static AttributeType GetAttributeFromName(const std::string &s)
Superclass::OffsetType OffsetType
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
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
void PrintSelf(std::ostream &os, Indent indent) const
virtual void CopyAttributesFrom(const LabelObjectType *lo)
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:184
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
Superclass::MatrixType MatrixType
const double & GetVariance() const
static const AttributeType SKEWNESS
static const AttributeType HISTOGRAM
const IndexType & GetMinimumIndex() const
const double & GetWeightedElongation() const