Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkStatisticsLabelObject.h

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

Generated at Fri Apr 16 19:45:51 2010 for ITK by doxygen 1.6.1 written by Dimitri van Heesch, © 1997-2000