ANIMA  4.0
animaComputeMahalanobisImagesFilter.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 <itkChiSquareDistribution.h>
7 #include <itkMahalanobisDistanceThresholdImageFunction.h>
8 #include <itkGaussianMembershipFunction.h>
9 #include <itkRescaleIntensityImageFilter.h>
11 
12 namespace anima
13 {
18 template <typename TInputImage, typename TMaskImage, typename TOutput = TInputImage>
20  public itk::ImageToImageFilter< TInputImage, TOutput >
21 {
22 public:
25  typedef itk::ImageToImageFilter< TInputImage, TOutput > Superclass;
26  typedef itk::SmartPointer<Self> Pointer;
27  typedef itk::SmartPointer<const Self> ConstPointer;
28 
30  itkNewMacro(Self)
31 
32 
33  itkTypeMacro(ComputeMahalanobisImagesFilter, ImageToImageFilter)
34 
35 
36  typedef TInputImage InputImageType;
37  typedef typename InputImageType::ConstPointer InputImageConstPointer;
38  typedef typename itk::ImageRegionConstIterator< InputImageType > InputConstIteratorType;
39 
41  typedef TMaskImage MaskImageType;
42  typedef typename itk::ImageRegionConstIterator< MaskImageType > MaskConstIteratorType;
43 
45  typedef TOutput OutputImageType;
46  typedef typename OutputImageType::Pointer OutputImagePointer;
47  typedef typename itk::ImageRegionIterator< OutputImageType > OutputIteratorType;
48  typedef typename OutputImageType::PixelType OutputPixelType;
49 
51  typedef typename Superclass::OutputImageRegionType OutputImageRegionType;
52 
53  typedef unsigned char PixelTypeUC;
54  typedef itk::Image <PixelTypeUC,3> ImageTypeUC;
55  typedef ImageTypeUC::Pointer ImagePointerUC;
56  typedef itk::ImageRegionConstIterator <ImageTypeUC> ImageConstIteratorTypeUC;
57 
59  typedef typename itk::RescaleIntensityImageFilter<TInputImage,ImageTypeUC> RescaleFilterType;
60 
61  typedef itk::VariableLengthVector<double> MeasurementVectorType;
62  typedef itk::Statistics::GaussianMembershipFunction< MeasurementVectorType > GaussianFunctionType;
63 
65  void SetInputImage1(const InputImageType* image);
66  void SetInputImage2(const InputImageType* image);
67  void SetInputImage3(const InputImageType* image);
68 
71  void SetMask(const TMaskImage* mask);
72 
75  void SetSolutionReadFilename(std::string filename) {m_SolutionReadFilename=filename;}
76 
77  void SetOutputMahaCSFFilename(std::string filename) {m_OutputMahaCSFFilename=filename;}
78  void SetOutputMahaGMFilename(std::string filename) {m_OutputMahaGMFilename=filename;}
79  void SetOutputMahaWMFilename(std::string filename) {m_OutputMahaWMFilename=filename;}
80 
81  void SetOutputMahaMaximumFilename(std::string filename) {m_OutputMahaMaximumFilename=filename;}
82  void SetOutputMahaMinimumFilename(std::string filename) {m_OutputMahaMinimumFilename=filename;}
83 
84  void WriteOutputs();
85 
86  void SetGaussianModel(std::vector<GaussianFunctionType::Pointer> solution) {m_GaussianModel=solution;}
87  std::vector<GaussianFunctionType::Pointer> GetSolutionGM() {return m_GaussianModel;}
88 
92 
95 
96  void SetTol(const double tol)
97  {
98  this->SetCoordinateTolerance(tol);
99  this->SetDirectionTolerance(tol);
100  m_Tol = tol;
101  }
102 
103  //Update progression of the process
104  static void eventCallback (itk::Object* caller, const itk::EventObject& event, void* clientData)
105  {
106  itk::ProcessObject * processObject = (itk::ProcessObject*) caller;
107  std::cout<<"\033[K\rProgression: "<<(int)(processObject->GetProgress() * 100)<<"%"<<std::flush;
108  }
109 
110  itkSetMacro(Verbose, bool)
111  itkGetMacro(Verbose, bool)
112 
113 protected:
115  {
116  this->SetNumberOfRequiredOutputs(5);
117  this->SetNumberOfRequiredInputs(4);
118 
119  this->SetNthOutput( 0, this->MakeOutput(0) );
120  this->SetNthOutput( 1, this->MakeOutput(1) );
121  this->SetNthOutput( 2, this->MakeOutput(2) );
122  this->SetNthOutput( 3, this->MakeOutput(3) );
123  this->SetNthOutput( 4, this->MakeOutput(4) );
124 
125  m_Verbose=false;
126 
127  m_Tol = 0.0001;
128 
129  m_NbTissus = 3; // 3 NABT tissus to estimate.
130  m_NbModalities = 3; // use of 3 images.
131 
132  this->SetNumberOfWorkUnits(itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads());
133 
134  }
135 
137  {
138  }
139 
140  typename InputImageType::ConstPointer GetInputImage1();
141  typename InputImageType::ConstPointer GetInputImage2();
142  typename InputImageType::ConstPointer GetInputImage3();
143 
144  typename TMaskImage::ConstPointer GetMask();
145 
147  itk::DataObject::Pointer MakeOutput(unsigned int idx);
148 
149  void BeforeThreadedGenerateData() ITK_OVERRIDE;
150  void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) ITK_OVERRIDE;
151 
152 private:
153  ITK_DISALLOW_COPY_AND_ASSIGN(ComputeMahalanobisImagesFilter);
154 
155  std::string m_SolutionReadFilename;
156 
157  unsigned int m_NbTissus;
158  unsigned int m_NbModalities;
159 
160  std::vector<double> m_Alphas;
161  std::vector<GaussianFunctionType::Pointer> m_GaussianModel;
162 
163  bool m_Verbose;
164  double m_Tol;
165 
166  std::string m_OutputMahaCSFFilename;
167  std::string m_OutputMahaGMFilename;
168  std::string m_OutputMahaWMFilename;
169 
170  std::string m_OutputMahaMinimumFilename;
171  std::string m_OutputMahaMaximumFilename;
172 
173  ImagePointerUC m_InputImage_1_UC;
174  ImagePointerUC m_InputImage_2_UC;
175  ImagePointerUC m_InputImage_3_UC;
176 };
177 
178 } // end of namespace anima
179 
itk::RescaleIntensityImageFilter< TInputImage, ImageTypeUC > RescaleFilterType
static void eventCallback(itk::Object *caller, const itk::EventObject &event, void *clientData)
void SetGaussianModel(std::vector< GaussianFunctionType::Pointer > solution)
STL namespace.
itk::ImageRegionIterator< OutputImageType > OutputIteratorType
void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) ITK_OVERRIDE
itk::Statistics::GaussianMembershipFunction< MeasurementVectorType > GaussianFunctionType
std::vector< GaussianFunctionType::Pointer > GetSolutionGM()
Compute the mahalanobis images from the NABT model.
itk::VariableLengthVector< double > MeasurementVectorType
itk::ImageToImageFilter< TInputImage, TOutput > Superclass
itk::ImageRegionConstIterator< MaskImageType > MaskConstIteratorType
itk::ImageRegionConstIterator< InputImageType > InputConstIteratorType
itk::ImageRegionConstIterator< ImageTypeUC > ImageConstIteratorTypeUC
itk::DataObject::Pointer MakeOutput(unsigned int idx)
Superclass::OutputImageRegionType OutputImageRegionType