ITK  6.0.0
Insight Toolkit
itkStatisticsLabelObject.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
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 * https://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
24namespace itk
25{
40template <typename TLabel, unsigned int VImageDimension>
41class ITK_TEMPLATE_EXPORT StatisticsLabelObject : public ShapeLabelObject<TLabel, VImageDimension>
42{
43public:
44 ITK_DISALLOW_COPY_AND_MOVE(StatisticsLabelObject);
45
49 using LabelObjectType = typename Superclass::LabelObjectType;
53
55 itkNewMacro(Self);
56
58 itkOverrideGetNameOfClassMacro(StatisticsLabelObject);
59
61
62 static constexpr unsigned int ImageDimension = VImageDimension;
63
64 using typename Superclass::IndexType;
65
67
68 using LabelType = TLabel;
69
70 using typename Superclass::LineType;
71
72 using typename Superclass::LengthType;
73
75
77
79
80 using typename Superclass::AttributeType;
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
101 GetAttributeFromName(const std::string & s)
102 {
103 if (s == "Minimum")
104 {
105 return MINIMUM;
106 }
107 else if (s == "Maximum")
108 {
109 return MAXIMUM;
110 }
111 else if (s == "Mean")
112 {
113 return MEAN;
114 }
115 else if (s == "Sum")
116 {
117 return SUM;
118 }
119 else if (s == "StandardDeviation")
120 {
121 return STANDARD_DEVIATION;
122 }
123 else if (s == "Variance")
124 {
125 return VARIANCE;
126 }
127 else if (s == "Median")
128 {
129 return MEDIAN;
130 }
131 else if (s == "MaximumIndex")
132 {
133 return MAXIMUM_INDEX;
134 }
135 else if (s == "MinimumIndex")
136 {
137 return MINIMUM_INDEX;
138 }
139 else if (s == "CenterOfGravity")
140 {
141 return CENTER_OF_GRAVITY;
142 }
143 /*
144 else if( s == "CentralMoments" )
145 {
146 return CENTRAL_MOMENTS;
147 }
148 */
149 else if (s == "WeightedPrincipalMoments")
150 {
151 return WEIGHTED_PRINCIPAL_MOMENTS;
152 }
153 else if (s == "WeightedPrincipalAxes")
154 {
155 return WEIGHTED_PRINCIPAL_AXES;
156 }
157 else if (s == "Kurtosis")
158 {
159 return KURTOSIS;
160 }
161 else if (s == "Skewness")
162 {
163 return SKEWNESS;
164 }
165 else if (s == "WeightedElongation")
166 {
167 return WEIGHTED_ELONGATION;
168 }
169 else if (s == "Histogram")
170 {
171 return HISTOGRAM;
172 }
173 else if (s == "WeightedFlatness")
174 {
175 return WEIGHTED_FLATNESS;
176 }
177 // can't recognize the name
178 return Superclass::GetAttributeFromName(s);
179 }
180
181 static std::string
183 {
184 switch (a)
185 {
186 case MINIMUM:
187 return "Minimum";
188 case MAXIMUM:
189 return "Maximum";
190 case MEAN:
191 return "Mean";
192 case SUM:
193 return "Sum";
194 case STANDARD_DEVIATION:
195 return "StandardDeviation";
196 case VARIANCE:
197 return "Variance";
198 case MEDIAN:
199 return "Median";
200 case MAXIMUM_INDEX:
201 return "MaximumIndex";
202 case MINIMUM_INDEX:
203 return "MinimumIndex";
204 case CENTER_OF_GRAVITY:
205 return "CenterOfGravity";
206 /* case CENTRAL_MOMENTS:
207 return "CentralMoments";*/
208 case WEIGHTED_PRINCIPAL_MOMENTS:
209 return "WeightedPrincipalMoments";
210 case WEIGHTED_PRINCIPAL_AXES:
211 return "WeightedPrincipalAxes";
212 case KURTOSIS:
213 return "Kurtosis";
214 case SKEWNESS:
215 return "Skewness";
216 case WEIGHTED_ELONGATION:
217 return "WeightedElongation";
218 case HISTOGRAM:
219 return "Histogram";
220 case WEIGHTED_FLATNESS:
221 return "WeightedFlatness";
222 }
223 // can't recognize the name
224 return Superclass::GetNameFromAttribute(a);
225 }
226
228
229 using typename Superclass::CentroidType;
230
231 template <typename TSourceLabelObject>
232 void
233 CopyAttributesFrom(const TSourceLabelObject * src)
234 {
235 Superclass::template CopyAttributesFrom<TSourceLabelObject>(src);
236
237 m_Minimum = src->GetMinimum();
238 m_Maximum = src->GetMaximum();
239 m_Mean = src->GetMean();
240 m_Sum = src->GetSum();
241 m_StandardDeviation = src->GetStandardDeviation();
242 m_Variance = src->GetVariance();
243 m_Median = src->GetMedian();
244 m_MaximumIndex = src->GetMaximumIndex();
245 m_MinimumIndex = src->GetMinimumIndex();
246 m_CenterOfGravity = src->GetCenterOfGravity();
247 // m_CentralMoments = src->GetCentralMoments();
248 m_WeightedPrincipalMoments = src->GetWeightedPrincipalMoments();
249 m_WeightedPrincipalAxes = src->GetWeightedPrincipalAxes();
250 m_Kurtosis = src->GetKurtosis();
251 m_Skewness = src->GetSkewness();
252 m_WeightedElongation = src->GetWeightedElongation();
253 m_Histogram = src->GetHistogram();
254 m_WeightedFlatness = src->GetWeightedFlatness();
255 }
256
257 template <typename TSourceLabelObject>
258 void
259 CopyAllFrom(const TSourceLabelObject * src)
260 {
261 itkAssertOrThrowMacro((src != nullptr), "Null Pointer");
262 this->template CopyLinesFrom<TSourceLabelObject>(src);
263 this->template CopyAttributesFrom<TSourceLabelObject>(src);
264 }
265
266 const double &
268 {
269 return m_Minimum;
270 }
271
272 void
273 SetMinimum(const double v)
274 {
275 m_Minimum = v;
276 }
277
278 const double &
280 {
281 return m_Maximum;
282 }
283
284 void
285 SetMaximum(const double v)
286 {
287 m_Maximum = v;
288 }
289
290 const double &
291 GetMean() const
292 {
293 return m_Mean;
294 }
295
296 void
297 SetMean(const double v)
298 {
299 m_Mean = v;
300 }
301
302 const double &
303 GetSum() const
304 {
305 return m_Sum;
306 }
307
308 void
309 SetSum(const double v)
310 {
311 m_Sum = v;
312 }
313
314 const double &
316 {
317 return m_StandardDeviation;
318 }
319
320 void
321 SetStandardDeviation(const double v)
322 {
323 m_StandardDeviation = v;
324 }
325
326 const double &
328 {
329 return m_Variance;
330 }
331
332 void
333 SetVariance(const double v)
334 {
335 m_Variance = v;
336 }
337
338 const double &
339 GetMedian() const
340 {
341 return m_Median;
342 }
343
344 void
345 SetMedian(const double v)
346 {
347 m_Median = v;
348 }
349
350 const IndexType &
352 {
353 return m_MaximumIndex;
354 }
355
356 void
358 {
359 m_MaximumIndex = v;
360 }
361
362 const IndexType &
364 {
365 return m_MinimumIndex;
366 }
367
368 void
370 {
371 m_MinimumIndex = v;
372 }
373
374 const PointType &
376 {
377 return m_CenterOfGravity;
378 }
379
380 void
382 {
383 m_CenterOfGravity = v;
384 }
385
386 /*
387 const MatrixType & GetCentralMoments() const
388 {
389 return m_CentralMoments;
390 }
391
392 void SetCentralMoments( const MatrixType & v )
393 {
394 m_CentralMoments = v;
395 }*/
396
397 const VectorType &
399 {
400 return m_WeightedPrincipalMoments;
401 }
402
403 void
405 {
406 m_WeightedPrincipalMoments = v;
407 }
408
409 const MatrixType &
411 {
412 return m_WeightedPrincipalAxes;
413 }
414
415 void
417 {
418 m_WeightedPrincipalAxes = v;
419 }
420
421 const double &
423 {
424 return m_Skewness;
425 }
426
427 void
428 SetSkewness(const double v)
429 {
430 m_Skewness = v;
431 }
432
433 const double &
435 {
436 return m_Kurtosis;
437 }
438
439 void
440 SetKurtosis(const double v)
441 {
442 m_Kurtosis = v;
443 }
444
445 const double &
447 {
448 return m_WeightedElongation;
449 }
450
451 void
452 SetWeightedElongation(const double v)
453 {
454 m_WeightedElongation = v;
455 }
456
457 const HistogramType *
459 {
460 return m_Histogram;
461 }
462
463 void
465 {
466 m_Histogram = v;
467 }
468
469 const double &
471 {
472 return m_WeightedFlatness;
473 }
474
475 void
476 SetWeightedFlatness(const double v)
477 {
478 m_WeightedFlatness = v;
479 }
480
481 // some helper methods - not really required, but really useful!
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 }
505
506 result->SetMatrix(matrix);
507 result->SetOffset(offset);
508
509 return result;
510 }
511
516 AffineTransformPointer
518 {
519 typename AffineTransformType::MatrixType matrix;
520 typename AffineTransformType::OffsetType offset;
521 for (unsigned int i = 0; i < ImageDimension; ++i)
522 {
523 offset[i] = m_CenterOfGravity[i];
524 for (unsigned int j = 0; j < ImageDimension; ++j)
525 {
526 matrix[j][i] = m_WeightedPrincipalAxes[i][j]; // Note the transposition
527 }
528 }
532 result->SetMatrix(matrix);
533 result->SetOffset(offset);
534
536 result->GetInverse(inverse);
537
538 return inverse;
539 }
540
541protected:
543 {
544 m_Minimum = 0;
545 m_Maximum = 0;
546 m_Mean = 0;
547 m_Sum = 0;
548 m_StandardDeviation = 0;
549 m_Variance = 0;
550 m_Median = 0;
551 m_MaximumIndex.Fill(0);
552 m_MinimumIndex.Fill(0);
553 m_CenterOfGravity.Fill(0);
554 // m_CentralMoments.Fill(0);
555 m_WeightedPrincipalMoments.Fill(0);
556 m_WeightedPrincipalAxes.Fill(0);
557 m_Kurtosis = 0;
558 m_Skewness = 0;
559 m_WeightedElongation = 0;
560 m_Histogram = nullptr;
561 m_WeightedFlatness = 0;
562 }
563
564 void
565 PrintSelf(std::ostream & os, Indent indent) const override
566 {
567 Superclass::PrintSelf(os, indent);
568
569 os << indent << "Minimum: " << m_Minimum << std::endl;
570 os << indent << "Maximum: " << m_Maximum << std::endl;
571 os << indent << "Mean: " << m_Mean << std::endl;
572 os << indent << "Sum: " << m_Sum << std::endl;
573 os << indent << "StandardDeviation: " << m_StandardDeviation << std::endl;
574 os << indent << "Variance: " << m_Variance << std::endl;
575 os << indent << "Median: " << m_Median << std::endl;
576 os << indent << "Skewness: " << m_Skewness << std::endl;
577 os << indent << "Kurtosis: " << m_Kurtosis << std::endl;
578 os << indent << "WeightedElongation: " << m_WeightedElongation << std::endl;
579 os << indent << "WeightedFlatness: " << m_WeightedFlatness << std::endl;
580 os << indent << "MaximumIndex: " << m_MaximumIndex << std::endl;
581 os << indent << "MinimumIndex: " << m_MinimumIndex << std::endl;
582 os << indent << "CenterOfGravity: " << m_CenterOfGravity << std::endl;
583 // os << indent << "CentralMoments: " << std::endl << m_CentralMoments;
584 os << indent << "WeightedPrincipalMoments: " << m_WeightedPrincipalMoments << std::endl;
585 os << indent << "WeightedPrincipalAxes: " << std::endl << m_WeightedPrincipalAxes;
586 itkPrintSelfObjectMacro(Histogram);
587 }
588
589private:
590 double m_Minimum{};
591 double m_Maximum{};
592 double m_Mean{};
593 double m_Sum{};
594 double m_StandardDeviation{};
595 double m_Variance{};
596 double m_Median{};
597 IndexType m_MaximumIndex{};
598 IndexType m_MinimumIndex{};
599 PointType m_CenterOfGravity{};
600 // MatrixType m_CentralMoments;
601 VectorType m_WeightedPrincipalMoments{};
602 MatrixType m_WeightedPrincipalAxes{};
603 double m_Skewness{};
604 double m_Kurtosis{};
605 double m_WeightedElongation{};
606
607 typename HistogramType::ConstPointer m_Histogram{};
608
609 double m_WeightedFlatness{};
610};
611} // end namespace itk
612
613#endif
An image region represents a structured region of data.
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Templated n-dimensional image to store labeled objects.
Definition: itkLabelMap.h:71
unsigned int AttributeType
Light weight base class for most itk classes.
A Label object to store the common attributes related to the shape of the object.
typename AffineTransformType::Pointer AffineTransformPointer
A Label object to store the common attributes related to the statistics of the object.
const PointType & GetCenterOfGravity() const
const double & GetVariance() const
const double & GetStandardDeviation() const
void SetWeightedPrincipalMoments(const VectorType &v)
void SetHistogram(const HistogramType *v)
void SetMinimumIndex(const IndexType &v)
const IndexType & GetMinimumIndex() const
const double & GetWeightedElongation() const
const double & GetSkewness() const
static AttributeType GetAttributeFromName(const std::string &s)
const IndexType & GetMaximumIndex() const
void PrintSelf(std::ostream &os, Indent indent) const override
void SetCenterOfGravity(const PointType &v)
AffineTransformPointer GetWeightedPrincipalAxesToPhysicalAxesTransform() const
void CopyAttributesFrom(const TSourceLabelObject *src)
void SetWeightedElongation(const double v)
const double & GetKurtosis() const
void SetMaximumIndex(const IndexType &v)
const HistogramType * GetHistogram() const
const double & GetWeightedFlatness() const
void SetStandardDeviation(const double v)
void SetWeightedFlatness(const double v)
void CopyAllFrom(const TSourceLabelObject *src)
AffineTransformPointer GetPhysicalAxesToWeightedPrincipalAxesTransform() const
static std::string GetNameFromAttribute(const AttributeType &a)
void SetWeightedPrincipalAxes(const MatrixType &v)
const VectorType & GetWeightedPrincipalMoments() const
const MatrixType & GetWeightedPrincipalAxes() const
This class stores measurement vectors in the context of n-dimensional histogram.
Definition: itkHistogram.h:78
Implements a weak reference to an object.
static Pointer New()
SmartPointer< Self > Pointer
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....