ITK  5.0.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:
44  ITK_DISALLOW_COPY_AND_ASSIGN(StatisticsLabelObject);
45 
53 
55  itkNewMacro(Self);
56 
58  itkTypeMacro(StatisticsLabelObject, LabelObject);
59 
61 
62  static constexpr unsigned int ImageDimension = VImageDimension;
63 
64  using IndexType = typename Superclass::IndexType;
65 
67 
68  using LabelType = TLabel;
69 
70  using LineType = typename Superclass::LineType;
71 
73 
75 
77 
79 
81  static constexpr AttributeType MINIMUM = 200;
82  static constexpr AttributeType MAXIMUM = 201;
83  static constexpr AttributeType MEAN = 202;
84  static constexpr AttributeType SUM = 203;
85  static constexpr AttributeType STANDARD_DEVIATION = 204;
86  static constexpr AttributeType VARIANCE = 205;
87  static constexpr AttributeType MEDIAN = 206;
88  static constexpr AttributeType MAXIMUM_INDEX = 207;
89  static constexpr AttributeType MINIMUM_INDEX = 208;
90  static constexpr AttributeType CENTER_OF_GRAVITY = 209;
91 // static constexpr AttributeType CENTRAL_MOMENTS = 210;
92  static constexpr AttributeType WEIGHTED_PRINCIPAL_MOMENTS = 211;
93  static constexpr AttributeType WEIGHTED_PRINCIPAL_AXES = 212;
94  static constexpr AttributeType KURTOSIS = 213;
95  static constexpr AttributeType SKEWNESS = 214;
96  static constexpr AttributeType WEIGHTED_ELONGATION = 215;
97  static constexpr AttributeType HISTOGRAM = 216;
98  static constexpr AttributeType WEIGHTED_FLATNESS = 217;
99 
100  static AttributeType GetAttributeFromName(const std::string & s)
101  {
102  if ( s == "Minimum" )
103  {
104  return MINIMUM;
105  }
106  else if ( s == "Maximum" )
107  {
108  return MAXIMUM;
109  }
110  else if ( s == "Mean" )
111  {
112  return MEAN;
113  }
114  else if ( s == "Sum" )
115  {
116  return SUM;
117  }
118  else if ( s == "StandardDeviation" )
119  {
120  return STANDARD_DEVIATION;
121  }
122  else if ( s == "Variance" )
123  {
124  return VARIANCE;
125  }
126  else if ( s == "Median" )
127  {
128  return MEDIAN;
129  }
130  else if ( s == "MaximumIndex" )
131  {
132  return MAXIMUM_INDEX;
133  }
134  else if ( s == "MinimumIndex" )
135  {
136  return MINIMUM_INDEX;
137  }
138  else if ( s == "CenterOfGravity" )
139  {
140  return CENTER_OF_GRAVITY;
141  }
142  /*
143  else if( s == "CentralMoments" )
144  {
145  return CENTRAL_MOMENTS;
146  }
147  */
148  else if ( s == "WeightedPrincipalMoments" )
149  {
151  }
152  else if ( s == "WeightedPrincipalAxes" )
153  {
155  }
156  else if ( s == "Kurtosis" )
157  {
158  return KURTOSIS;
159  }
160  else if ( s == "Skewness" )
161  {
162  return SKEWNESS;
163  }
164  else if ( s == "WeightedElongation" )
165  {
166  return WEIGHTED_ELONGATION;
167  }
168  else if ( s == "Histogram" )
169  {
170  return HISTOGRAM;
171  }
172  else if ( s == "WeightedFlatness" )
173  {
174  return WEIGHTED_FLATNESS;
175  }
176  // can't recognize the name
178  }
179 
180  static std::string GetNameFromAttribute(const AttributeType & a)
181  {
182  switch ( a )
183  {
184  case MINIMUM:
185  return "Minimum";
186  break;
187  case MAXIMUM:
188  return "Maximum";
189  break;
190  case MEAN:
191  return "Mean";
192  break;
193  case SUM:
194  return "Sum";
195  break;
196  case STANDARD_DEVIATION:
197  return "StandardDeviation";
198  break;
199  case VARIANCE:
200  return "Variance";
201  break;
202  case MEDIAN:
203  return "Median";
204  break;
205  case MAXIMUM_INDEX:
206  return "MaximumIndex";
207  break;
208  case MINIMUM_INDEX:
209  return "MinimumIndex";
210  break;
211  case CENTER_OF_GRAVITY:
212  return "CenterOfGravity";
213  break;
214  /* case CENTRAL_MOMENTS:
215  return "CentralMoments";
216  break;*/
218  return "WeightedPrincipalMoments";
219  break;
221  return "WeightedPrincipalAxes";
222  break;
223  case KURTOSIS:
224  return "Kurtosis";
225  break;
226  case SKEWNESS:
227  return "Skewness";
228  break;
229  case WEIGHTED_ELONGATION:
230  return "WeightedElongation";
231  break;
232  case HISTOGRAM:
233  return "Histogram";
234  break;
235  case WEIGHTED_FLATNESS:
236  return "WeightedFlatness";
237  break;
238  }
239  // can't recognize the name
241  }
242 
244 
246 
247  template< typename TSourceLabelObject >
248  void CopyAttributesFrom( const TSourceLabelObject * src )
249  {
250  Superclass::template CopyAttributesFrom<TSourceLabelObject>(src);
251 
252  m_Minimum = src->GetMinimum();
253  m_Maximum = src->GetMaximum();
254  m_Mean = src->GetMean();
255  m_Sum = src->GetSum();
256  m_StandardDeviation = src->GetStandardDeviation();
257  m_Variance = src->GetVariance();
258  m_Median = src->GetMedian();
259  m_MaximumIndex = src->GetMaximumIndex();
260  m_MinimumIndex = src->GetMinimumIndex();
261  m_CenterOfGravity = src->GetCenterOfGravity();
262  // m_CentralMoments = src->GetCentralMoments();
263  m_WeightedPrincipalMoments = src->GetWeightedPrincipalMoments();
264  m_WeightedPrincipalAxes = src->GetWeightedPrincipalAxes();
265  m_Kurtosis = src->GetKurtosis();
266  m_Skewness = src->GetSkewness();
267  m_WeightedElongation = src->GetWeightedElongation();
268  m_Histogram = src->GetHistogram();
269  m_WeightedFlatness = src->GetWeightedFlatness();
270  }
271 
272  template< typename TSourceLabelObject >
273  void CopyAllFrom(const TSourceLabelObject *src)
274  {
275  itkAssertOrThrowMacro ( ( src != nullptr ), "Null Pointer" );
276  this->template CopyLinesFrom<TSourceLabelObject>( src );
277  this->template CopyAttributesFrom<TSourceLabelObject>( src );
278  }
279 
280  const double & GetMinimum() const
281  {
282  return m_Minimum;
283  }
284 
285  void SetMinimum(const double & v)
286  {
287  m_Minimum = v;
288  }
289 
290  const double & GetMaximum() const
291  {
292  return m_Maximum;
293  }
294 
295  void SetMaximum(const double & v)
296  {
297  m_Maximum = v;
298  }
299 
300  const double & GetMean() const
301  {
302  return m_Mean;
303  }
304 
305  void SetMean(const double & v)
306  {
307  m_Mean = v;
308  }
309 
310  const double & GetSum() const
311  {
312  return m_Sum;
313  }
314 
315  void SetSum(const double & v)
316  {
317  m_Sum = v;
318  }
319 
320  const double & GetStandardDeviation() const
321  {
322  return m_StandardDeviation;
323  }
324 
325  void SetStandardDeviation(const double & v)
326  {
328  }
329 
330  const double & GetVariance() const
331  {
332  return m_Variance;
333  }
334 
335  void SetVariance(const double & v)
336  {
337  m_Variance = v;
338  }
339 
340  const double & GetMedian() const
341  {
342  return m_Median;
343  }
344 
345  void SetMedian(const double & v)
346  {
347  m_Median = v;
348  }
349 
350  const IndexType & GetMaximumIndex() const
351  {
352  return m_MaximumIndex;
353  }
354 
355  void SetMaximumIndex(const IndexType & v)
356  {
357  m_MaximumIndex = v;
358  }
359 
360  const IndexType & GetMinimumIndex() const
361  {
362  return m_MinimumIndex;
363  }
364 
365  void SetMinimumIndex(const IndexType & v)
366  {
367  m_MinimumIndex = v;
368  }
369 
371  {
372  return m_CenterOfGravity;
373  }
374 
376  {
377  m_CenterOfGravity = v;
378  }
379 
380  /*
381  const MatrixType & GetCentralMoments() const
382  {
383  return m_CentralMoments;
384  }
385 
386  void SetCentralMoments( const MatrixType & v )
387  {
388  m_CentralMoments = v;
389  }*/
390 
392  {
394  }
395 
397  {
399  }
400 
402  {
404  }
405 
407  {
409  }
410 
411  const double & GetSkewness() const
412  {
413  return m_Skewness;
414  }
415 
416  void SetSkewness(const double & v)
417  {
418  m_Skewness = v;
419  }
420 
421  const double & GetKurtosis() const
422  {
423  return m_Kurtosis;
424  }
425 
426  void SetKurtosis(const double & v)
427  {
428  m_Kurtosis = v;
429  }
430 
431  const double & GetWeightedElongation() const
432  {
433  return m_WeightedElongation;
434  }
435 
436  void SetWeightedElongation(const double & v)
437  {
439  }
440 
441  const HistogramType * GetHistogram() const
442  {
443  return m_Histogram;
444  }
445 
447  {
448  m_Histogram = v;
449  }
450 
451  const double & GetWeightedFlatness() const
452  {
453  return m_WeightedFlatness;
454  }
455 
456  void SetWeightedFlatness(const double & v)
457  {
458  m_WeightedFlatness = v;
459  }
460 
461  // some helper methods - not really required, but really useful!
465 
470  {
471  typename AffineTransformType::MatrixType matrix;
472  typename AffineTransformType::OffsetType offset;
473  for ( unsigned int i = 0; i < ImageDimension; i++ )
474  {
475  offset[i] = m_CenterOfGravity[i];
476  for ( unsigned int j = 0; j < ImageDimension; j++ )
477  {
478  matrix[j][i] = m_WeightedPrincipalAxes[i][j]; // Note the transposition
479  }
480  }
482 
484 
485  result->SetMatrix(matrix);
486  result->SetOffset(offset);
487 
488  return result;
489  }
490 
496  {
497  typename AffineTransformType::MatrixType matrix;
498  typename AffineTransformType::OffsetType offset;
499  for ( unsigned int i = 0; i < ImageDimension; i++ )
500  {
501  offset[i] = m_CenterOfGravity[i];
502  for ( unsigned int j = 0; j < ImageDimension; j++ )
503  {
504  matrix[j][i] = m_WeightedPrincipalAxes[i][j]; // Note the transposition
505  }
506  }
508 
510  result->SetMatrix(matrix);
511  result->SetOffset(offset);
512 
514  result->GetInverse(inverse);
515 
516  return inverse;
517  }
518 
519 protected:
521  {
522  m_Minimum = 0;
523  m_Maximum = 0;
524  m_Mean = 0;
525  m_Sum = 0;
527  m_Variance = 0;
528  m_Median = 0;
529  m_MaximumIndex.Fill(0);
530  m_MinimumIndex.Fill(0);
532  // m_CentralMoments.Fill(0);
535  m_Kurtosis = 0;
536  m_Skewness = 0;
538  m_Histogram = nullptr;
539  m_WeightedFlatness = 0;
540  }
541 
542  void PrintSelf(std::ostream & os, Indent indent) const override
543  {
544  Superclass::PrintSelf(os, indent);
545 
546  os << indent << "Minimum: " << m_Minimum << std::endl;
547  os << indent << "Maximum: " << m_Maximum << std::endl;
548  os << indent << "Mean: " << m_Mean << std::endl;
549  os << indent << "Sum: " << m_Sum << std::endl;
550  os << indent << "StandardDeviation: " << m_StandardDeviation << std::endl;
551  os << indent << "Variance: " << m_Variance << std::endl;
552  os << indent << "Median: " << m_Median << std::endl;
553  os << indent << "Skewness: " << m_Skewness << std::endl;
554  os << indent << "Kurtosis: " << m_Kurtosis << std::endl;
555  os << indent << "WeightedElongation: " << m_WeightedElongation << std::endl;
556  os << indent << "WeightedFlatness: " << m_WeightedFlatness << std::endl;
557  os << indent << "MaximumIndex: " << m_MaximumIndex << std::endl;
558  os << indent << "MinimumIndex: " << m_MinimumIndex << std::endl;
559  os << indent << "CenterOfGravity: " << m_CenterOfGravity << std::endl;
560  // os << indent << "CentralMoments: " << std::endl << m_CentralMoments;
561  os << indent << "WeightedPrincipalMoments: " << m_WeightedPrincipalMoments << std::endl;
562  os << indent << "WeightedPrincipalAxes: " << std::endl << m_WeightedPrincipalAxes;
563  itkPrintSelfObjectMacro( Histogram );
564  }
565 
566 private:
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 constexpr AttributeType WEIGHTED_FLATNESS
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)
typename Superclass::IndexType IndexType
const PointType & GetCenterOfGravity() const
static constexpr AttributeType VARIANCE
static Pointer New()
typename Superclass::AttributeType AttributeType
void CopyAttributesFrom(const TSourceLabelObject *src)
void SetMaximumIndex(const IndexType &v)
const HistogramType * GetHistogram() const
static constexpr AttributeType STANDARD_DEVIATION
This class stores measurement vectors in the context of n-dimensional histogram.
Definition: itkHistogram.h:77
An image region represents a structured region of data.
void PrintSelf(std::ostream &os, Indent indent) const override
static constexpr AttributeType KURTOSIS
static constexpr AttributeType WEIGHTED_ELONGATION
Implements a weak reference to an object.
static constexpr AttributeType SKEWNESS
void Fill(const ValueType &)
typename Superclass::OffsetType OffsetType
static AttributeType GetAttributeFromName(const std::string &s)
SmartPointer< Self > Pointer
void PrintSelf(std::ostream &os, Indent indent) const override
A Label object to store the common attributes related to the statistics of the object.
typename Superclass::LengthType LengthType
typename Superclass::MatrixType MatrixType
void SetHistogram(const HistogramType *v)
const double & GetMedian() const
AffineTransformPointer GetPhysicalAxesToWeightedPrincipalAxesTransform() const
static constexpr AttributeType MEAN
const double & GetKurtosis() const
const double & GetSkewness() const
const VectorType & GetWeightedPrincipalMoments() const
static AttributeType GetAttributeFromName(const std::string &s)
static constexpr AttributeType MAXIMUM
Point< double, VImageDimension > CentroidType
A Label object to store the common attributes related to the shape of the object. ...
static constexpr unsigned int ImageDimension
void SetMinimumIndex(const IndexType &v)
const MatrixType & GetWeightedPrincipalAxes() const
static constexpr AttributeType MINIMUM_INDEX
const double & GetStandardDeviation() const
static constexpr AttributeType MEDIAN
typename Superclass::LineType LineType
typename LineType::LengthType LengthType
static constexpr AttributeType CENTER_OF_GRAVITY
void SetWeightedElongation(const double &v)
static constexpr AttributeType MINIMUM
The base class for the representation of an labeled binary object in an image.
static constexpr AttributeType WEIGHTED_PRINCIPAL_AXES
HistogramType::ConstPointer m_Histogram
void SetWeightedPrincipalAxes(const MatrixType &v)
void Fill(IndexValueType value)
Definition: itkIndex.h:257
static constexpr AttributeType WEIGHTED_PRINCIPAL_MOMENTS
const IndexType & GetMaximumIndex() const
const double & GetWeightedFlatness() const
typename AffineTransformType::Pointer AffineTransformPointer
const double & GetMaximum() const
Control indentation during Print() invocation.
Definition: itkIndent.h:49
void Fill(const T &value)
Definition: itkMatrix.h:186
static constexpr AttributeType HISTOGRAM
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 constexpr AttributeType SUM
typename Superclass::LabelObjectType LabelObjectType
static std::string GetNameFromAttribute(const AttributeType &a)
typename Superclass::AttributeType AttributeType
const double & GetVariance() const
void CopyAllFrom(const TSourceLabelObject *src)
const IndexType & GetMinimumIndex() const
const double & GetWeightedElongation() const
static constexpr AttributeType MAXIMUM_INDEX