ANIMA  4.0
animaHierarchicalInitializer.h
Go to the documentation of this file.
1 #pragma once
2 
7 
8 #include <itkHistogram.h>
9 #include <itkListSample.h>
10 #include <itkDenseFrequencyContainer2.h>
11 #include <itkSampleToHistogramFilter.h>
12 #include <itkMinimumMaximumImageCalculator.h>
13 #include <itkImageRegionIterator.h>
14 #include <itkMaskImageFilter.h>
15 
16 
17 namespace anima
18 {
34 template <typename TInputImage, typename TMaskImage>
36 {
37 public:
38 
41  typedef itk::ProcessObject Superclass;
42  typedef itk::SmartPointer <Self> Pointer;
43  typedef itk::SmartPointer <const Self> ConstPointer;
44 
46  itkNewMacro(Self)
47 
48 
49  itkTypeMacro(HierarchicalInitializer, itk::ProcessObject)
50 
51  typedef double PixelTypeD;
52  typedef itk::Image <PixelTypeD,3> ImageTypeD;
53  typedef itk::ImageRegionIterator <ImageTypeD> ImageIteratorTypeD;
54  typedef itk::ImageRegionIterator< ImageTypeD > InputIteratorTypeD;
55 
57  typedef TInputImage InputImageType;
58  typedef typename InputImageType::ConstPointer InputImageConstPointer;
59  typedef typename InputImageType::Pointer InputImagePointer;
60  typedef typename InputImageType::PixelType InputImagePixelType;
61  typedef typename itk::ImageRegionIterator< InputImageType > InputIteratorType;
62  typedef typename itk::ImageRegionConstIterator< InputImageType > InputConstIteratorType;
63 
65  typedef TMaskImage MaskImageType;
66  typedef typename MaskImageType::ConstPointer MaskImageConstPointer;
67  typedef typename itk::ImageRegionConstIterator< MaskImageType > MaskConstIteratorType;
68 
69  typedef anima::ImageClassifierFilter<InputImageType,InputImageType> ImageClassifierType;
70  typedef anima::GaussianREMEstimator<InputImageType,MaskImageType> GaussianREMEstimatorType;
71  typedef anima::ClassificationStrategy<InputImageType,MaskImageType> ClassificationStrategyType;
72  typedef itk::MaskImageFilter< InputImageType, InputImageType > MaskFilterType;
73  typedef itk::MinimumMaximumImageCalculator<InputImageType> MinMaxCalculatorType;
74 
75  typedef std::map<double, std::vector<GaussianFunctionType::Pointer> > ModelMap;
76  typedef std::map<double, std::vector<double> > ModelMap2;
77 
79  void SetInputImage1(const TInputImage* image);
80  void SetInputImage2(const TInputImage* image);
81  void SetInputImage3(const TInputImage* image);
82  void SetInputImage4(const TInputImage* image);
83  void SetInputImage5(const TInputImage* image);
84 
85  typename TInputImage::ConstPointer GetInputImage1();
86  typename TInputImage::ConstPointer GetInputImage2();
87  typename TInputImage::ConstPointer GetInputImage3();
88  typename TInputImage::ConstPointer GetInputImage4();
89  typename TInputImage::ConstPointer GetInputImage5();
90 
93  void SetMask(const TMaskImage* mask);
94  typename TMaskImage::ConstPointer GetMask();
95 
96  double regionMedianValue(itk::Image< double, 3 >::Pointer image, typename TInputImage::Pointer mask );
97 
98  void Update() ITK_OVERRIDE;
99 
120  void ComputeSolution1D();
121 
125 
136  void ComputeHistogram();
137 
140  void ComputeVariances();
141 
145 
146  //Update progression of the process
147  static void eventCallback (itk::Object* caller, const itk::EventObject& event, void* clientData)
148  {
149  itk::ProcessObject * processObject = (itk::ProcessObject*) caller;
150  std::cout<<"\033[K\rProgression: "<<(int)(processObject->GetProgress() * 100)<<"%"<<std::flush;
151  }
152 
153  itkSetMacro(Tol, double)
154  itkGetMacro(Tol, double)
155 
156  itkSetMacro(ThirdIsFLAIR, bool)
157  itkGetMacro(ThirdIsFLAIR, bool)
158 
159  itkSetMacro(Robust, double)
160  itkGetMacro(Robust, double)
161 
162 protected:
164  {
165  m_ThirdIsFLAIR = true;
166  m_Robust = 0.01;
167  m_NbInputs = 1;
168  m_NbMaxImages = 6;
169  m_NbClasses = 3;
170  m_NumberOfModalities = 3;
171  m_IndexImage1 = m_NbMaxImages, m_IndexImage2 = m_NbMaxImages, m_IndexImage3 = m_NbMaxImages, m_IndexImage4 = m_NbMaxImages, m_IndexImage5 = m_NbMaxImages, m_IndexImagem_NbMaxImages = m_NbMaxImages;
172  }
174 
175 private:
176  ITK_DISALLOW_COPY_AND_ASSIGN(HierarchicalInitializer);
177 
178  std::vector<InputImageConstPointer> m_ImagesVector; //Order must be "T1","T2","FLAIR or PD"
179  bool m_ThirdIsFLAIR;
180  double m_Robust;
181 
182  unsigned int m_NbInputs, m_NbMaxImages;
183  unsigned int m_IndexImage1, m_IndexImage2, m_IndexImage3, m_IndexImage4,m_IndexImage5, m_IndexImagem_NbMaxImages;
184  unsigned int m_NbClasses, m_NumberOfModalities;
185 
186  std::vector<GaussianFunctionType::Pointer> m_Solution1D;
187  std::vector<double> m_Solution1DAlphas;
188 
189  std::vector<InputImagePointer> m_ImagesClasses;
190  std::vector< std::vector<double> > m_Stds;
191  std::vector< std::vector<double> > m_SelectedMax;
192 
193  double m_Tol;
194 };
195 
196 }
197 
itk::Image< PixelTypeD, 3 > ImageTypeD
TInputImage::ConstPointer GetInputImage4()
std::map< double, std::vector< double > > ModelMap2
void SetInputImage5(const TInputImage *image)
STL namespace.
Class performing a robust expectation-maximation (REM) algorithm. Allow finding the 3-classes NABT mo...
TInputImage::ConstPointer GetInputImage2()
itk::ImageRegionIterator< ImageTypeD > ImageIteratorTypeD
TInputImage::ConstPointer GetInputImage5()
itk::ImageRegionIterator< ImageTypeD > InputIteratorTypeD
void SetInputImage2(const TInputImage *image)
TInputImage::ConstPointer GetInputImage3()
Gaussian model initializers Model Initializer represents the processes computing a gaussian model tha...
itk::MaskImageFilter< InputImageType, InputImageType > MaskFilterType
void SetInputImage1(const TInputImage *image)
itk::ImageRegionIterator< InputImageType > InputIteratorType
double regionMedianValue(itk::Image< double, 3 >::Pointer image, typename TInputImage::Pointer mask)
Class initializing a gaussian mixture with hierarchical information It uses &#39;a priori&#39; knowledge of t...
InputImageType::PixelType InputImagePixelType
TInputImage::ConstPointer GetInputImage1()
void SetInputImage4(const TInputImage *image)
void SetInputImage3(const TInputImage *image)
Classify each voxels into one of the given GMM classes.
itk::ImageRegionConstIterator< InputImageType > InputConstIteratorType
InputImageType::ConstPointer InputImageConstPointer
itk::ImageRegionConstIterator< MaskImageType > MaskConstIteratorType
itk::Statistics::GaussianMembershipFunction< MeasurementVectorType > GaussianFunctionType
itk::SmartPointer< const Self > ConstPointer
static void eventCallback(itk::Object *caller, const itk::EventObject &event, void *clientData)
itk::MinimumMaximumImageCalculator< InputImageType > MinMaxCalculatorType
std::map< double, std::vector< GaussianFunctionType::Pointer > > ModelMap
MaskImageType::ConstPointer MaskImageConstPointer