ANIMA  4.0
animaGaussianEMEstimator.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "itkProcessObject.h"
4 #include "itkGaussianMembershipFunction.h"
5 
6 namespace anima
7 {
8 
12 template <typename TInputImage, typename TMaskImage>
13 class GaussianEMEstimator : public itk::ProcessObject
14 {
15 public:
16 
19  typedef itk::ProcessObject Superclass;
20  typedef itk::SmartPointer <Self> Pointer;
21  typedef itk::SmartPointer <const Self> ConstPointer;
22 
24  itkNewMacro(Self);
25 
27  itkTypeMacro(GaussianEMEstimator, itk::ProcessObject);
28 
30  typedef TInputImage InputImageType;
31  typedef typename InputImageType::ConstPointer InputImageConstPointer;
32  typedef typename itk::ImageRegionConstIterator< InputImageType > InputConstIteratorType;
33 
35  typedef TMaskImage MaskImageType;
36  typedef typename itk::ImageRegionIterator< MaskImageType > MaskIteratorType;
37  typedef typename itk::ImageRegionConstIterator< MaskImageType > MaskConstIteratorType;
38 
39  typedef double Ocurrences;
40  typedef unsigned short MeasureType;
41  typedef std::vector<MeasureType> Intensities;
42  typedef std::map< Intensities, std::vector<Ocurrences> > GenericContainer;
43  typedef std::map<Intensities,Ocurrences> Histogram;
44 
45  typedef double NumericType;
46  typedef itk::VariableLengthVector<NumericType> MeasurementVectorType;
47  typedef itk::Statistics::GaussianMembershipFunction< MeasurementVectorType > GaussianFunctionType;
48 
51  void SetInitialGaussianModel( std::vector<GaussianFunctionType::Pointer > & theValue ){this->m_GaussianModel = theValue;}
52  void SetInitialAlphas( std::vector<double> &theValue ){m_Alphas = theValue;}
53 
54  std::vector<GaussianFunctionType::Pointer> GetGaussianModel(){return this->m_GaussianModel;}
55  std::vector<double> GetAlphas(){return m_Alphas;}
56 
60 
61  virtual void Update() ITK_OVERRIDE;
62 
63  virtual bool maximization(std::vector<GaussianFunctionType::Pointer> &newModel, std::vector<double> &newAlphas);
64  virtual double expectation();
65 
66  double likelihood(GaussianFunctionType::CovarianceMatrixType *invCovariance=NULL, double *detCovariance=NULL);
67 
68  double computeDistance(std::vector<GaussianFunctionType::Pointer> &newModel);
69 
71 
72  void createJointHistogram();
73 
75  void SetInputImage1(const TInputImage* image);
76  void SetInputImage2(const TInputImage* image);
77  void SetInputImage3(const TInputImage* image);
78  void SetInputImage4(const TInputImage* image);
79  void SetInputImage5(const TInputImage* image);
80 
81  typename TInputImage::ConstPointer GetInputImage1();
82  typename TInputImage::ConstPointer GetInputImage2();
83  typename TInputImage::ConstPointer GetInputImage3();
84  typename TInputImage::ConstPointer GetInputImage4();
85  typename TInputImage::ConstPointer GetInputImage5();
86 
89  void SetMask(const TMaskImage* mask);
90  typename TMaskImage::ConstPointer GetMask();
91 
92  itkSetMacro(Likelihood, double);
93  itkGetMacro(Likelihood, double);
94 
95  itkSetMacro(ModelMinDistance, double);
96  itkGetMacro(ModelMinDistance, double);
97 
98  itkSetMacro(MaxIterations, unsigned int);
99  itkGetMacro(MaxIterations, unsigned int);
100 
101  itkSetMacro(Verbose, bool);
102  itkGetMacro(Verbose, bool);
103 
104 protected:
105 
106  GaussianEMEstimator(const Self&); //purposely not implemented
107  void operator=(const Self&); //purposely not implemented
108 
110  {
111  m_ModelMinDistance=1e-9;
112  m_MaxIterations=1000;
113  m_Verbose=false;
114  m_NbInputs=1;
115  m_nbMaxImages=6;
122  }
124 
125  GenericContainer m_APosterioriProbability;
126 
128 
129  unsigned int m_MaxIterations;
130 
133  std::vector<double> m_Alphas;
134  std::vector<GaussianFunctionType::Pointer> m_GaussianModel;
135 
139  Histogram m_JointHistogram;
141 
142  std::vector<InputImageConstPointer > m_ImagesVector;
143 
144  bool m_Verbose;
145  unsigned int m_nbMaxImages;
146  unsigned int m_NbInputs;
148  double m_Likelihood;
149 
150 };
151 
152 }
153 
154 
itk::VariableLengthVector< NumericType > MeasurementVectorType
InputImageType::ConstPointer InputImageConstPointer
std::vector< MeasureType > Intensities
void SetInputImage1(const TInputImage *image)
Gaussian Model estimator Class performing expectation-maximation algorithm.
Histogram m_JointHistogram
joint histogram The points stored here will be used for estimate de model
TInputImage::ConstPointer GetInputImage1()
Histogram GetJointHistogram()
return joint histogram
void SetMask(const TMaskImage *mask)
itk::ImageRegionConstIterator< MaskImageType > MaskConstIteratorType
void SetInitialAlphas(std::vector< double > &theValue)
virtual void Update() ITK_OVERRIDE
TInputImage::ConstPointer GetInputImage2()
void SetInputImage5(const TInputImage *image)
double likelihood(GaussianFunctionType::CovarianceMatrixType *invCovariance=NULL, double *detCovariance=NULL)
itk::SmartPointer< Self > Pointer
itk::ImageRegionIterator< MaskImageType > MaskIteratorType
virtual bool maximization(std::vector< GaussianFunctionType::Pointer > &newModel, std::vector< double > &newAlphas)
void SetInputImage4(const TInputImage *image)
std::vector< InputImageConstPointer > m_ImagesVector
itk::SmartPointer< const Self > ConstPointer
std::map< Intensities, Ocurrences > Histogram
itk::ImageRegionConstIterator< InputImageType > InputConstIteratorType
TInputImage::ConstPointer GetInputImage5()
std::vector< GaussianFunctionType::Pointer > m_GaussianModel
TInputImage::ConstPointer GetInputImage3()
void SetInitialGaussianModel(std::vector< GaussianFunctionType::Pointer > &theValue)
Set model to be estimated.
TInputImage::ConstPointer GetInputImage4()
void operator=(const Self &)
GenericContainer GetAPosterioriProbability()
double computeDistance(std::vector< GaussianFunctionType::Pointer > &newModel)
std::vector< double > m_Alphas
model to be estimated (and solution if already run)
std::vector< double > GetAlphas()
void SetInputImage2(const TInputImage *image)
std::vector< GaussianFunctionType::Pointer > GetGaussianModel()
TMaskImage::ConstPointer GetMask()
itk::Statistics::GaussianMembershipFunction< MeasurementVectorType > GaussianFunctionType
void SetInputImage3(const TInputImage *image)
std::map< Intensities, std::vector< Ocurrences > > GenericContainer