ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkStatisticsLabelObject_h 00019 #define __itkStatisticsLabelObject_h 00020 00021 #include "itkShapeLabelObject.h" 00022 #include "itkHistogram.h" 00023 00024 namespace itk 00025 { 00040 template< class TLabel, unsigned int VImageDimension > 00041 class ITK_EXPORT StatisticsLabelObject:public ShapeLabelObject< TLabel, VImageDimension > 00042 { 00043 public: 00045 typedef StatisticsLabelObject Self; 00046 typedef ShapeLabelObject< TLabel, VImageDimension > Superclass; 00047 typedef typename Superclass::LabelObjectType LabelObjectType; 00048 typedef SmartPointer< Self > Pointer; 00049 typedef SmartPointer< const Self > ConstPointer; 00050 typedef WeakPointer< const Self > ConstWeakPointer; 00051 00053 itkNewMacro(Self); 00054 00056 itkTypeMacro(StatisticsLabelObject, LabelObject); 00057 00058 typedef LabelMap< Self > LabelMapType; 00059 00060 itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension); 00061 00062 typedef typename Superclass::IndexType IndexType; 00063 00064 typedef Point< double, itkGetStaticConstMacro(ImageDimension) > PointType; 00065 00066 typedef TLabel LabelType; 00067 00068 typedef typename Superclass::LineType LineType; 00069 00070 typedef typename Superclass::LengthType LengthType; 00071 00072 typedef Matrix< double, itkGetStaticConstMacro(ImageDimension), itkGetStaticConstMacro(ImageDimension) > MatrixType; 00073 00074 typedef Vector< double, itkGetStaticConstMacro(ImageDimension) > VectorType; 00075 00076 typedef Statistics::Histogram< double > HistogramType; 00077 00078 typedef typename Superclass::AttributeType AttributeType; 00079 itkStaticConstMacro(MINIMUM, AttributeType, 200); 00080 itkStaticConstMacro(MAXIMUM, AttributeType, 201); 00081 itkStaticConstMacro(MEAN, AttributeType, 202); 00082 itkStaticConstMacro(SUM, AttributeType, 203); 00083 itkStaticConstMacro(STANDARD_DEVIATION, AttributeType, 204); 00084 itkStaticConstMacro(VARIANCE, AttributeType, 205); 00085 itkStaticConstMacro(MEDIAN, AttributeType, 206); 00086 itkStaticConstMacro(MAXIMUM_INDEX, AttributeType, 207); 00087 itkStaticConstMacro(MINIMUM_INDEX, AttributeType, 208); 00088 itkStaticConstMacro(CENTER_OF_GRAVITY, AttributeType, 209); 00089 // itkStaticConstMacro(CENTRAL_MOMENTS, AttributeType, 210); 00090 itkStaticConstMacro(WEIGHTED_PRINCIPAL_MOMENTS, AttributeType, 211); 00091 itkStaticConstMacro(WEIGHTED_PRINCIPAL_AXES, AttributeType, 212); 00092 itkStaticConstMacro(KURTOSIS, AttributeType, 213); 00093 itkStaticConstMacro(SKEWNESS, AttributeType, 214); 00094 itkStaticConstMacro(WEIGHTED_ELONGATION, AttributeType, 215); 00095 itkStaticConstMacro(HISTOGRAM, AttributeType, 216); 00096 itkStaticConstMacro(WEIGHTED_FLATNESS, AttributeType, 217); 00097 00098 static AttributeType GetAttributeFromName(const std::string & s) 00099 { 00100 if ( s == "Minimum" ) 00101 { 00102 return MINIMUM; 00103 } 00104 else if ( s == "Maximum" ) 00105 { 00106 return MAXIMUM; 00107 } 00108 else if ( s == "Mean" ) 00109 { 00110 return MEAN; 00111 } 00112 else if ( s == "Sum" ) 00113 { 00114 return SUM; 00115 } 00116 else if ( s == "StandardDeviation" ) 00117 { 00118 return STANDARD_DEVIATION; 00119 } 00120 else if ( s == "Variance" ) 00121 { 00122 return VARIANCE; 00123 } 00124 else if ( s == "Median" ) 00125 { 00126 return MEDIAN; 00127 } 00128 else if ( s == "MaximumIndex" ) 00129 { 00130 return MAXIMUM_INDEX; 00131 } 00132 else if ( s == "MinimumIndex" ) 00133 { 00134 return MINIMUM_INDEX; 00135 } 00136 else if ( s == "CenterOfGravity" ) 00137 { 00138 return CENTER_OF_GRAVITY; 00139 } 00140 /* 00141 else if( s == "CentralMoments" ) 00142 { 00143 return CENTRAL_MOMENTS; 00144 } 00145 */ 00146 else if ( s == "WeightedPrincipalMoments" ) 00147 { 00148 return WEIGHTED_PRINCIPAL_MOMENTS; 00149 } 00150 else if ( s == "WeightedPrincipalAxes" ) 00151 { 00152 return WEIGHTED_PRINCIPAL_AXES; 00153 } 00154 else if ( s == "Kurtosis" ) 00155 { 00156 return KURTOSIS; 00157 } 00158 else if ( s == "Skewness" ) 00159 { 00160 return SKEWNESS; 00161 } 00162 else if ( s == "WeightedElongation" ) 00163 { 00164 return WEIGHTED_ELONGATION; 00165 } 00166 else if ( s == "Histogram" ) 00167 { 00168 return HISTOGRAM; 00169 } 00170 else if ( s == "WeightedFlatness" ) 00171 { 00172 return WEIGHTED_FLATNESS; 00173 } 00174 // can't recognize the name 00175 return Superclass::GetAttributeFromName(s); 00176 } 00177 00178 static std::string GetNameFromAttribute(const AttributeType & a) 00179 { 00180 switch ( a ) 00181 { 00182 case MINIMUM: 00183 return "Minimum"; 00184 break; 00185 case MAXIMUM: 00186 return "Maximum"; 00187 break; 00188 case MEAN: 00189 return "Mean"; 00190 break; 00191 case SUM: 00192 return "Sum"; 00193 break; 00194 case STANDARD_DEVIATION: 00195 return "StandardDeviation"; 00196 break; 00197 case VARIANCE: 00198 return "Variance"; 00199 break; 00200 case MEDIAN: 00201 return "Median"; 00202 break; 00203 case MAXIMUM_INDEX: 00204 return "MaximumIndex"; 00205 break; 00206 case MINIMUM_INDEX: 00207 return "MinimumIndex"; 00208 break; 00209 case CENTER_OF_GRAVITY: 00210 return "CenterOfGravity"; 00211 break; 00212 /* case CENTRAL_MOMENTS: 00213 return "CentralMoments"; 00214 break;*/ 00215 case WEIGHTED_PRINCIPAL_MOMENTS: 00216 return "WeightedPrincipalMoments"; 00217 break; 00218 case WEIGHTED_PRINCIPAL_AXES: 00219 return "WeightedPrincipalAxes"; 00220 break; 00221 case KURTOSIS: 00222 return "Kurtosis"; 00223 break; 00224 case SKEWNESS: 00225 return "Skewness"; 00226 break; 00227 case WEIGHTED_ELONGATION: 00228 return "WeightedElongation"; 00229 break; 00230 case HISTOGRAM: 00231 return "Histogram"; 00232 break; 00233 case WEIGHTED_FLATNESS: 00234 return "WeightedFlatness"; 00235 break; 00236 } 00237 // can't recognize the name 00238 return Superclass::GetNameFromAttribute(a); 00239 } 00240 00241 typedef ImageRegion< itkGetStaticConstMacro(ImageDimension) > RegionType; 00242 00243 typedef typename Superclass::CentroidType CentroidType; 00244 00245 virtual void CopyAttributesFrom(const LabelObjectType *lo) 00246 { 00247 Superclass::CopyAttributesFrom(lo); 00248 00249 // copy the data of the current type if possible 00250 const Self *src = dynamic_cast< const Self * >( lo ); 00251 if ( src == NULL ) 00252 { 00253 return; 00254 } 00255 m_Minimum = src->m_Minimum; 00256 m_Maximum = src->m_Maximum; 00257 m_Mean = src->m_Mean; 00258 m_Sum = src->m_Sum; 00259 m_StandardDeviation = src->m_StandardDeviation; 00260 m_Variance = src->m_Variance; 00261 m_Median = src->m_Median; 00262 m_MaximumIndex = src->m_MaximumIndex; 00263 m_MinimumIndex = src->m_MinimumIndex; 00264 m_CenterOfGravity = src->m_CenterOfGravity; 00265 // m_CentralMoments = src->m_CentralMoments; 00266 m_WeightedPrincipalMoments = src->m_WeightedPrincipalMoments; 00267 m_WeightedPrincipalAxes = src->m_WeightedPrincipalAxes; 00268 m_Kurtosis = src->m_Kurtosis; 00269 m_Skewness = src->m_Skewness; 00270 m_WeightedElongation = src->m_WeightedElongation; 00271 m_Histogram = src->m_Histogram; 00272 m_WeightedFlatness = src->m_WeightedFlatness; 00273 } 00274 00275 const double & GetMinimum() const 00276 { 00277 return m_Minimum; 00278 } 00279 00280 void SetMinimum(const double & v) 00281 { 00282 m_Minimum = v; 00283 } 00284 00285 const double & GetMaximum() const 00286 { 00287 return m_Maximum; 00288 } 00289 00290 void SetMaximum(const double & v) 00291 { 00292 m_Maximum = v; 00293 } 00294 00295 const double & GetMean() const 00296 { 00297 return m_Mean; 00298 } 00299 00300 void SetMean(const double & v) 00301 { 00302 m_Mean = v; 00303 } 00304 00305 const double & GetSum() const 00306 { 00307 return m_Sum; 00308 } 00309 00310 void SetSum(const double & v) 00311 { 00312 m_Sum = v; 00313 } 00314 00315 const double & GetStandardDeviation() const 00316 { 00317 return m_StandardDeviation; 00318 } 00319 00320 void SetStandardDeviation(const double & v) 00321 { 00322 m_StandardDeviation = v; 00323 } 00324 00325 const double & GetVariance() const 00326 { 00327 return m_Variance; 00328 } 00329 00330 void SetVariance(const double & v) 00331 { 00332 m_Variance = v; 00333 } 00334 00335 const double & GetMedian() const 00336 { 00337 return m_Median; 00338 } 00339 00340 void SetMedian(const double & v) 00341 { 00342 m_Median = v; 00343 } 00344 00345 const IndexType & GetMaximumIndex() const 00346 { 00347 return m_MaximumIndex; 00348 } 00349 00350 void SetMaximumIndex(const IndexType & v) 00351 { 00352 m_MaximumIndex = v; 00353 } 00354 00355 const IndexType & GetMinimumIndex() const 00356 { 00357 return m_MinimumIndex; 00358 } 00359 00360 void SetMinimumIndex(const IndexType & v) 00361 { 00362 m_MinimumIndex = v; 00363 } 00364 00365 const PointType & GetCenterOfGravity() const 00366 { 00367 return m_CenterOfGravity; 00368 } 00369 00370 void SetCenterOfGravity(const PointType & v) 00371 { 00372 m_CenterOfGravity = v; 00373 } 00374 00375 /* 00376 const MatrixType & GetCentralMoments() const 00377 { 00378 return m_CentralMoments; 00379 } 00380 00381 void SetCentralMoments( const MatrixType & v ) 00382 { 00383 m_CentralMoments = v; 00384 }*/ 00385 00386 const VectorType & GetWeightedPrincipalMoments() const 00387 { 00388 return m_WeightedPrincipalMoments; 00389 } 00390 00391 void SetWeightedPrincipalMoments(const VectorType & v) 00392 { 00393 m_WeightedPrincipalMoments = v; 00394 } 00395 00396 const MatrixType & GetWeightedPrincipalAxes() const 00397 { 00398 return m_WeightedPrincipalAxes; 00399 } 00400 00401 void SetWeightedPrincipalAxes(const MatrixType & v) 00402 { 00403 m_WeightedPrincipalAxes = v; 00404 } 00405 00406 const double & GetSkewness() const 00407 { 00408 return m_Skewness; 00409 } 00410 00411 void SetSkewness(const double & v) 00412 { 00413 m_Skewness = v; 00414 } 00415 00416 const double & GetKurtosis() const 00417 { 00418 return m_Kurtosis; 00419 } 00420 00421 void SetKurtosis(const double & v) 00422 { 00423 m_Kurtosis = v; 00424 } 00425 00426 const double & GetWeightedElongation() const 00427 { 00428 return m_WeightedElongation; 00429 } 00430 00431 void SetWeightedElongation(const double & v) 00432 { 00433 m_WeightedElongation = v; 00434 } 00435 00436 const HistogramType * GetHistogram() const 00437 { 00438 return m_Histogram; 00439 } 00440 00441 void SetHistogram(const HistogramType *v) 00442 { 00443 m_Histogram = v; 00444 } 00445 00446 const double & GetWeightedFlatness() const 00447 { 00448 return m_WeightedFlatness; 00449 } 00450 00451 void SetWeightedFlatness(const double & v) 00452 { 00453 m_WeightedFlatness = v; 00454 } 00455 00456 // some helper methods - not really required, but really useful! 00458 typedef AffineTransform< double, itkGetStaticConstMacro(ImageDimension) > AffineTransformType; 00459 typedef typename AffineTransformType::Pointer AffineTransformPointer; 00460 00464 AffineTransformPointer GetWeightedPrincipalAxesToPhysicalAxesTransform() const 00465 { 00466 typename AffineTransformType::MatrixType matrix; 00467 typename AffineTransformType::OffsetType offset; 00468 for ( unsigned int i = 0; i < ImageDimension; i++ ) 00469 { 00470 offset[i] = m_CenterOfGravity[i]; 00471 for ( unsigned int j = 0; j < ImageDimension; j++ ) 00472 { 00473 matrix[j][i] = m_WeightedPrincipalAxes[i][j]; // Note the transposition 00474 } 00475 } 00477 00478 AffineTransformPointer result = AffineTransformType::New(); 00479 00480 result->SetMatrix(matrix); 00481 result->SetOffset(offset); 00482 00483 return result; 00484 } 00485 00490 AffineTransformPointer GetPhysicalAxesToWeightedPrincipalAxesTransform(void) const 00491 { 00492 typename AffineTransformType::MatrixType matrix; 00493 typename AffineTransformType::OffsetType offset; 00494 for ( unsigned int i = 0; i < ImageDimension; i++ ) 00495 { 00496 offset[i] = m_CenterOfGravity[i]; 00497 for ( unsigned int j = 0; j < ImageDimension; j++ ) 00498 { 00499 matrix[j][i] = m_WeightedPrincipalAxes[i][j]; // Note the transposition 00500 } 00501 } 00503 00504 AffineTransformPointer result = AffineTransformType::New(); 00505 result->SetMatrix(matrix); 00506 result->SetOffset(offset); 00507 00508 AffineTransformPointer inverse = AffineTransformType::New(); 00509 result->GetInverse(inverse); 00510 00511 return inverse; 00512 } 00513 00514 protected: 00515 StatisticsLabelObject() 00516 { 00517 m_Minimum = 0; 00518 m_Maximum = 0; 00519 m_Mean = 0; 00520 m_Sum = 0; 00521 m_StandardDeviation = 0; 00522 m_Variance = 0; 00523 m_Median = 0; 00524 m_MaximumIndex.Fill(0); 00525 m_MinimumIndex.Fill(0); 00526 m_CenterOfGravity.Fill(0); 00527 // m_CentralMoments.Fill(0); 00528 m_WeightedPrincipalMoments.Fill(0); 00529 m_WeightedPrincipalAxes.Fill(0); 00530 m_Kurtosis = 0; 00531 m_Skewness = 0; 00532 m_WeightedElongation = 0; 00533 m_Histogram = NULL; 00534 m_WeightedFlatness = 0; 00535 } 00536 00537 void PrintSelf(std::ostream & os, Indent indent) const 00538 { 00539 Superclass::PrintSelf(os, indent); 00540 00541 os << indent << "Minimum: " << m_Minimum << std::endl; 00542 os << indent << "Maximum: " << m_Maximum << std::endl; 00543 os << indent << "Mean: " << m_Mean << std::endl; 00544 os << indent << "Sum: " << m_Sum << std::endl; 00545 os << indent << "StandardDeviation: " << m_StandardDeviation << std::endl; 00546 os << indent << "Variance: " << m_Variance << std::endl; 00547 os << indent << "Median: " << m_Median << std::endl; 00548 os << indent << "Skewness: " << m_Skewness << std::endl; 00549 os << indent << "Kurtosis: " << m_Kurtosis << std::endl; 00550 os << indent << "WeightedElongation: " << m_WeightedElongation << std::endl; 00551 os << indent << "WeightedFlatness: " << m_WeightedFlatness << std::endl; 00552 os << indent << "MaximumIndex: " << m_MaximumIndex << std::endl; 00553 os << indent << "MinimumIndex: " << m_MinimumIndex << std::endl; 00554 os << indent << "CenterOfGravity: " << m_CenterOfGravity << std::endl; 00555 // os << indent << "CentralMoments: " << std::endl << m_CentralMoments; 00556 os << indent << "WeightedPrincipalMoments: " << m_WeightedPrincipalMoments << std::endl; 00557 os << indent << "WeightedPrincipalAxes: " << std::endl << m_WeightedPrincipalAxes; 00558 os << indent << "Histogram: "; 00559 if ( m_Histogram.IsNull() ) 00560 { 00561 os << "NULL" << std::endl; 00562 } 00563 else 00564 { 00565 m_Histogram->Print(os, indent); 00566 } 00567 } 00568 00569 private: 00570 StatisticsLabelObject(const Self &); //purposely not implemented 00571 void operator=(const Self &); //purposely not implemented 00572 00573 double m_Minimum; 00574 double m_Maximum; 00575 double m_Mean; 00576 double m_Sum; 00577 double m_StandardDeviation; 00578 double m_Variance; 00579 double m_Median; 00580 IndexType m_MaximumIndex; 00581 IndexType m_MinimumIndex; 00582 PointType m_CenterOfGravity; 00583 // MatrixType m_CentralMoments; 00584 VectorType m_WeightedPrincipalMoments; 00585 MatrixType m_WeightedPrincipalAxes; 00586 double m_Skewness; 00587 double m_Kurtosis; 00588 double m_WeightedElongation; 00589 00590 typename HistogramType::ConstPointer m_Histogram; 00591 00592 double m_WeightedFlatness; 00593 }; 00594 } // end namespace itk 00595 00596 #endif 00597