ANIMA  4.0
animaComputeSolution.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <itkImageToImageFilter.h>
4 #include <itkImageRegionIterator.h>
5 #include <itkImageRegionConstIterator.h>
6 #include <itkCommand.h>
7 #include <itkCSVArray2DFileReader.h>
8 #include <itkCSVNumericObjectFileWriter.h>
9 #include <itkRescaleIntensityImageFilter.h>
10 #include <itkGaussianMembershipFunction.h>
11 
14 #include "animaAtlasInitializer.h"
16 
17 namespace anima
18 {
19 
25 template <typename TInputImage, typename TMaskImage, typename TAtlasImage = TInputImage>
27  public itk::ProcessObject
28 {
29 public:
32  typedef itk::ProcessObject Superclass;
33  typedef itk::SmartPointer<Self> Pointer;
34  typedef itk::SmartPointer<const Self> ConstPointer;
35 
37  itkNewMacro(Self)
38 
39 
40  itkTypeMacro(ComputeSolution, itk::ProcessObject)
41 
42 
43  typedef TInputImage InputImageType;
44  typedef typename InputImageType::ConstPointer InputImageConstPointer;
45  typedef typename itk::ImageRegionConstIterator< InputImageType > InputConstIteratorType;
46 
48  typedef TMaskImage MaskImageType;
49 
50  typedef unsigned char PixelTypeUC;
51  typedef itk::Image <PixelTypeUC,3> ImageTypeUC;
52  typedef ImageTypeUC::Pointer ImagePointerUC;
53 
54  typedef AtlasInitializer<ImageTypeUC,MaskImageType,TAtlasImage> AtlasInitializerType;
55  typedef HierarchicalInitializer<ImageTypeUC,MaskImageType> HierarchicalType;
56  typedef GaussianREMEstimator<ImageTypeUC,MaskImageType> GaussianREMEstimatorType;
57  typedef GaussianEMEstimator<ImageTypeUC,MaskImageType> GaussianEMEstimatorType;
58 
60  typedef typename itk::RescaleIntensityImageFilter<TInputImage,ImageTypeUC> RescaleFilterType;
61 
62  typedef double NumericType;
63  typedef itk::VariableLengthVector<NumericType> MeasurementVectorType;
64  typedef itk::Statistics::GaussianMembershipFunction< MeasurementVectorType > GaussianFunctionType;
65 
67  void SetInputImage1(const InputImageType* image);
68  void SetInputImage2(const InputImageType* image);
69  void SetInputImage3(const InputImageType* image);
70 
73  void SetMask(const TMaskImage* mask);
74 
77  void SetInputCSFAtlas(const TAtlasImage* atlas);
78  void SetInputGMAtlas(const TAtlasImage* atlas);
79  void SetInputWMAtlas(const TAtlasImage* atlas);
80 
81  void SetSolutionWriteFilename(std::string filename) {m_SolutionWriteFilename=filename;}
82  void SetSolutionReadFilename(std::string filename) {m_SolutionReadFilename=filename;}
83 
84  void WriteOutputs();
85 
86  std::vector<GaussianFunctionType::Pointer> GetGaussianModel() {return m_GaussianModel;}
87  void SetGaussianModel(std::vector<GaussianFunctionType::Pointer> model) {m_GaussianModel = model;}
88 
89  std::vector<double> GetAlphas() {return m_Alphas;}
90  void SetAlphas(std::vector<double> alpha) {m_Alphas = alpha;}
91 
92  virtual void Update() ITK_OVERRIDE;
93  int ReadSolution(std::string filename);
94  int WriteSolution(std::string filename);
95  int PrintSolution(std::vector<double> alphas, std::vector<GaussianFunctionType::Pointer> model);
96  void SortGaussianModel();
97 
98  //Update progression of the process
99  static void eventCallback (itk::Object* caller, const itk::EventObject& event, void* clientData)
100  {
101  itk::ProcessObject * processObject = (itk::ProcessObject*) caller;
102  std::cout<<"\033[K\rProgression: "<<(int)(processObject->GetProgress() * 100)<<"%"<<std::flush;
103  }
104 
105  itkSetMacro(InitMethodType, unsigned int)
106  itkGetMacro(InitMethodType, unsigned int)
107 
108  itkSetMacro(RejRatioHierar, double)
109  itkGetMacro(RejRatioHierar, double)
110 
111  itkSetMacro(MinDistance, double)
112  itkGetMacro(MinDistance, double)
113 
114  itkSetMacro(EmIter, int)
115  itkGetMacro(EmIter, int)
116 
117  itkSetMacro(RejRatio, double)
118  itkGetMacro(RejRatio, double)
119 
120  itkSetMacro(EmIter_concentration, int)
121  itkGetMacro(EmIter_concentration, int)
122 
123  itkSetMacro(EM_before_concentration, bool)
124  itkGetMacro(EM_before_concentration, bool)
125 
126  itkSetMacro(UseT2, bool)
127  itkGetMacro(UseT2, bool)
128 
129  itkSetMacro(UseDP, bool)
130  itkGetMacro(UseDP, bool)
131 
132  itkSetMacro(UseFLAIR, bool)
133  itkGetMacro(UseFLAIR, bool)
134 
135  itkSetMacro(Verbose, bool)
136  itkGetMacro(Verbose, bool)
137 
138  itkSetMacro(Tol, double)
139  itkGetMacro(Tol, double)
140 
141 protected:
143  {
144  this->SetNumberOfRequiredInputs(4);
145 
146  m_InitMethodType = 2;
147  m_RejRatio=0.2;
148  m_EmIter=100;
149  m_EmIter_concentration=100;
150  m_MinDistance=0.0001;
151 
152  m_RejRatioHierar=0.01;
153  m_Verbose=false;
154 
155  m_UseT2 = false;
156  m_UseDP = false;
157  m_UseFLAIR = false;
158  m_SolutionSet = false;
159 
160  m_Tol = 0.0001;
161  m_NbTissus = 3; // 3 NABT tissus to estimate.
162  m_NbModalities = 3; // use of 3 images.
163 
164  this->SetNumberOfWorkUnits(itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads());
165  }
166 
168  {
169  }
170 
171  typename InputImageType::ConstPointer GetInputImage1();
172  typename InputImageType::ConstPointer GetInputImage2();
173  typename InputImageType::ConstPointer GetInputImage3();
174 
175  typename MaskImageType::ConstPointer GetMask();
176 
177  typename TAtlasImage::ConstPointer GetInputCSFAtlas();
178  typename TAtlasImage::ConstPointer GetInputGMAtlas();
179  typename TAtlasImage::ConstPointer GetInputWMAtlas();
180 
181  void CheckInputs(void);
182  void RescaleImages(void);
183 
184 private:
185  ITK_DISALLOW_COPY_AND_ASSIGN(ComputeSolution);
186 
187  bool m_UseT2;
188  bool m_UseDP;
189  bool m_UseFLAIR;
190 
191  unsigned int m_InitMethodType;
192  double m_RejRatioHierar;
193  double m_MinDistance;
194  int m_EmIter;
195  double m_RejRatio;
196  int m_EmIter_concentration;
197  bool m_EM_before_concentration;
198 
199  bool m_SolutionSet;
200 
201  std::vector<GaussianFunctionType::Pointer> m_GaussianModel;
202  std::vector<double> m_Alphas;
203  std::string m_SolutionReadFilename;
204  std::string m_SolutionWriteFilename;
205 
206  unsigned int m_NbTissus;
207  unsigned int m_NbModalities;
208 
209  bool m_Verbose;
210 
211  ImagePointerUC m_InputImage_T1_UC;
212  ImagePointerUC m_InputImage_T2_DP_UC;
213  ImagePointerUC m_InputImage_DP_FLAIR_UC;
214 
215  double m_Tol;
216 };
217 
218 } // end of namespace anima
219 
220 #include "animaComputeSolution.hxx"
itk::RescaleIntensityImageFilter< TInputImage, ImageTypeUC > RescaleFilterType
Gaussian Model estimator Class performing expectation-maximation algorithm.
void SetGaussianModel(std::vector< GaussianFunctionType::Pointer > model)
void SetInputImage2(const InputImageType *image)
itk::SmartPointer< const Self > ConstPointer
static void eventCallback(itk::Object *caller, const itk::EventObject &event, void *clientData)
virtual void Update() ITK_OVERRIDE
itk::Statistics::GaussianMembershipFunction< MeasurementVectorType > GaussianFunctionType
STL namespace.
Class performing a robust expectation-maximation (REM) algorithm. Allow finding the 3-classes NABT mo...
Class computing the 3-class GMM respresenting the NABT, where each Gaussian represents one of the bra...
InputImageType::ConstPointer GetInputImage2()
void SetMask(const TMaskImage *mask)
InputImageType::ConstPointer GetInputImage3()
TAtlasImage::ConstPointer GetInputWMAtlas()
void SetInputGMAtlas(const TAtlasImage *atlas)
itk::ImageRegionConstIterator< InputImageType > InputConstIteratorType
TAtlasImage::ConstPointer GetInputCSFAtlas()
TAtlasImage::ConstPointer GetInputGMAtlas()
InputImageType::ConstPointer InputImageConstPointer
ImageTypeUC::Pointer ImagePointerUC
void SetSolutionReadFilename(std::string filename)
std::vector< double > GetAlphas()
Class initializing a gaussian mixture with hierarchical information It uses &#39;a priori&#39; knowledge of t...
int ReadSolution(std::string filename)
itk::Image< PixelTypeUC, 3 > ImageTypeUC
std::vector< GaussianFunctionType::Pointer > GetGaussianModel()
itk::SmartPointer< Self > Pointer
MaskImageType::ConstPointer GetMask()
int WriteSolution(std::string filename)
void SetAlphas(std::vector< double > alpha)
void SetInputWMAtlas(const TAtlasImage *atlas)
int PrintSolution(std::vector< double > alphas, std::vector< GaussianFunctionType::Pointer > model)
itk::VariableLengthVector< NumericType > MeasurementVectorType
void SetInputImage1(const InputImageType *image)
void SetInputImage3(const InputImageType *image)
itk::ProcessObject Superclass
void SetSolutionWriteFilename(std::string filename)
void SetInputCSFAtlas(const TAtlasImage *atlas)
InputImageType::ConstPointer GetInputImage1()