ITK  4.8.0
Insight Segmentation and Registration Toolkit
itkImageMomentsCalculator.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 itkImageMomentsCalculator_h
19 #define itkImageMomentsCalculator_h
20 
21 #include "itkAffineTransform.h"
22 #include "itkImage.h"
23 #include "itkSpatialObject.h"
24 
25 #include "vnl/vnl_vector_fixed.h"
26 #include "vnl/vnl_matrix_fixed.h"
27 #include "vnl/vnl_diag_matrix.h"
28 
29 namespace itk
30 {
59 template< typename TImage >
61 {
62 public:
65  typedef Object Superclass;
68 
70  itkNewMacro(Self);
71 
73  itkTypeMacro(ImageMomentsCalculator, Object);
74 
76  itkStaticConstMacro(ImageDimension, unsigned int,
77  TImage::ImageDimension);
78 
80  typedef double ScalarType;
81 
84 
87 
91 
93  typedef Matrix< ScalarType,
94  itkGetStaticConstMacro(ImageDimension),
95  itkGetStaticConstMacro(ImageDimension) > MatrixType;
96 
98  typedef TImage ImageType;
99 
101  typedef typename ImageType::Pointer ImagePointer;
102  typedef typename ImageType::ConstPointer ImageConstPointer;
103 
107 
109  virtual void SetImage(const ImageType *image)
110  {
111  if ( m_Image != image )
112  {
113  m_Image = image;
114  this->Modified();
115  m_Valid = false;
116  }
117  }
119 
121  virtual void SetSpatialObjectMask(const SpatialObject< itkGetStaticConstMacro(ImageDimension) > *so)
122  {
123  if ( m_SpatialObjectMask != so )
124  {
125  m_SpatialObjectMask = so;
126  this->Modified();
127  m_Valid = false;
128  }
129  }
131 
137  void Compute();
138 
143  ScalarType GetTotalMass() const;
144 
150  VectorType GetFirstMoments() const;
151 
158 
164 
170 
178 
193 
198 
204 
205 protected:
207  virtual ~ImageMomentsCalculator();
208  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
209 
210 private:
211  ImageMomentsCalculator(const Self &); //purposely not implemented
212  void operator=(const Self &); //purposely not implemented
213 
214  bool m_Valid; // Have moments been computed yet?
215  ScalarType m_M0; // Zeroth moment
216  VectorType m_M1; // First moments about origin
217  MatrixType m_M2; // Second moments about origin
218  VectorType m_Cg; // Center of gravity (physical units)
219  MatrixType m_Cm; // Second central moments (physical)
220  VectorType m_Pm; // Principal moments (physical)
221  MatrixType m_Pa; // Principal axes (physical)
222 
225 }; // class ImageMomentsCalculator
226 } // end namespace itk
227 
228 #ifndef ITK_MANUAL_INSTANTIATION
229 #include "itkImageMomentsCalculator.hxx"
230 #endif
231 
232 #endif /* itkImageMomentsCalculator_h */
SpatialObjectType::ConstPointer SpatialObjectConstPointer
MatrixType GetPrincipalAxes() const
A templated class holding a M x N size Matrix.
Definition: itkMatrix.h:46
Light weight base class for most itk classes.
MatrixType GetSecondMoments() const
SmartPointer< const Self > ConstPointer
VectorType GetFirstMoments() const
AffineTransformPointer GetPhysicalAxesToPrincipalAxesTransform() const
void operator=(const Self &)
static const unsigned int ImageDimension
VectorType GetCenterOfGravity() const
SpatialObjectType::Pointer SpatialObjectPointer
virtual void PrintSelf(std::ostream &os, Indent indent) const override
virtual void SetSpatialObjectMask(const SpatialObject< itkGetStaticConstMacro(ImageDimension) > *so)
VectorType GetPrincipalMoments() const
SpatialObjectConstPointer m_SpatialObjectMask
Matrix< ScalarType, itkGetStaticConstMacro(ImageDimension), itkGetStaticConstMacro(ImageDimension) > MatrixType
Compute moments of an n-dimensional image.
Implementation of the composite pattern.
SpatialObject< itkGetStaticConstMacro(ImageDimension) > SpatialObjectType
MatrixType GetCentralMoments() const
AffineTransform< double, itkGetStaticConstMacro(ImageDimension) > AffineTransformType
virtual void Modified() const
ImageType::ConstPointer ImageConstPointer
ScalarType GetTotalMass() const
ImageMomentsCalculator< TImage > Self
Control indentation during Print() invocation.
Definition: itkIndent.h:49
AffineTransformType::Pointer AffineTransformPointer
AffineTransformPointer GetPrincipalAxesToPhysicalAxesTransform() const
virtual void SetImage(const ImageType *image)
Base class for most ITK classes.
Definition: itkObject.h:57
Vector< ScalarType, itkGetStaticConstMacro(ImageDimension) > VectorType