ANIMA  4.0
animaImageClassifierFilter.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include <itkImageToImageFilter.h>
5 #include <itkGaussianMembershipFunction.h>
6 
7 namespace anima
8 {
14 template <typename TInput, typename TMask, typename TOutput = TInput>
16  public itk::ImageToImageFilter< TInput ,TOutput >
17 {
18 public:
21  typedef itk::ImageToImageFilter< TInput , TOutput > Superclass;
22  typedef itk::SmartPointer<Self> Pointer;
23  typedef itk::SmartPointer<const Self> ConstPointer;
24 
26  itkNewMacro(Self)
27 
28 
29  itkTypeMacro(ImageClassifierFilter, ImageToImageFilter)
30 
31 
32  typedef typename TInput::ConstPointer InputImageConstPointer;
33  typedef typename itk::ImageRegionConstIterator< TInput > InputConstIteratorType;
34 
36  typedef typename itk::ImageRegionConstIterator< TMask > MaskConstIteratorType;
37 
38  typedef typename TOutput::Pointer OutputImagePointer;
39  typedef typename TOutput::ConstPointer OutputImageConstPointer;
40  typedef typename itk::ImageRegionIterator< TOutput > OutputIteratorType;
41 
42  typedef double NumericType;
43  typedef itk::VariableSizeMatrix<NumericType> DoubleVariableSizeMatrixType;
44 
45  typedef itk::VariableLengthVector<double> MeasurementVectorType;
46  typedef itk::Statistics::GaussianMembershipFunction< MeasurementVectorType > GaussianFunctionType;
47 
48  void SetTol(const double tol)
49  {
50  this->SetCoordinateTolerance(tol);
51  this->SetDirectionTolerance(tol);
52  }
53 
55  void SetInputImage1(const TInput* image);
56  void SetInputImage2(const TInput* image);
57  void SetInputImage3(const TInput* image);
58  void SetInputImage4(const TInput* image);
59  void SetInputImage5(const TInput* image);
60 
63  void SetMask(const TMask* mask);
64 
66  typedef typename Superclass::OutputImageRegionType OutputImageRegionType;
67 
68  itkSetMacro(Verbose, bool)
69  itkGetMacro(Verbose, bool)
70 
71  void WriteOutputs();
72  void SetGaussianModel(std::vector<GaussianFunctionType::Pointer> &model) {m_GaussianModel=model;}
73  void SetAlphas(std::vector<double> &model) {m_Alphas=model;}
74  void SetOutputFilename(std::string filename){m_OutputFilename=filename;}
75  std::vector<GaussianFunctionType::Pointer> GetGaussiabModel() {return m_GaussianModel;}
76  std::vector<double> GetAlphas() {return m_Alphas;}
77 
78 protected:
80  {
81  this->SetNumberOfRequiredOutputs(1);
82  this->SetNumberOfRequiredInputs(2);
83 
84  m_NbInputs = 2;
85  m_NbMaxImages = 7;
86  m_IndexImage1=m_NbMaxImages, m_IndexImage2=m_NbMaxImages, m_IndexImage3=m_NbMaxImages, m_IndexImage4=m_NbMaxImages,m_IndexImage5=m_NbMaxImages, m_IndexImage6=m_NbMaxImages;
87  m_Verbose=false;
88  this->SetNumberOfWorkUnits(itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads());
89  }
90 
92  {
93  }
94 
95  typename TInput::ConstPointer GetInputImage1();
96  typename TInput::ConstPointer GetInputImage2();
97  typename TInput::ConstPointer GetInputImage3();
98  typename TInput::ConstPointer GetInputImage4();
99  typename TInput::ConstPointer GetInputImage5();
100 
101  typename TMask::ConstPointer GetMask();
102 
103  void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) ITK_OVERRIDE;
104  double probability(DoubleVariableSizeMatrixType &point, GaussianFunctionType::Pointer model);
105 
106 private:
107  ITK_DISALLOW_COPY_AND_ASSIGN(ImageClassifierFilter);
108 
109  std::vector<double> m_Alphas;
110  std::vector<GaussianFunctionType::Pointer> m_GaussianModel;
111 
112  std::vector<typename TInput::ConstPointer> m_ImagesVector;
113  std::string m_OutputFilename;
114 
115  unsigned int m_NbInputs, m_NbMaxImages;
116  unsigned int m_IndexImage1, m_IndexImage2, m_IndexImage3, m_IndexImage4,m_IndexImage5, m_IndexImage6;
117 
118  bool m_Verbose;
119 };
120 
121 } // end of namespace anima
122 
itk::Statistics::GaussianMembershipFunction< MeasurementVectorType > GaussianFunctionType
itk::VariableSizeMatrix< NumericType > DoubleVariableSizeMatrixType
double probability(DoubleVariableSizeMatrixType &point, GaussianFunctionType::Pointer model)
void SetInputImage5(const TInput *image)
Superclass::OutputImageRegionType OutputImageRegionType
void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) ITK_OVERRIDE
itk::VariableLengthVector< double > MeasurementVectorType
void SetInputImage4(const TInput *image)
void SetAlphas(std::vector< double > &model)
TOutput::ConstPointer OutputImageConstPointer
void SetInputImage2(const TInput *image)
itk::ImageToImageFilter< TInput, TOutput > Superclass
void SetOutputFilename(std::string filename)
itk::ImageRegionConstIterator< TMask > MaskConstIteratorType
itk::ImageRegionIterator< TOutput > OutputIteratorType
void SetInputImage1(const TInput *image)
itk::SmartPointer< const Self > ConstPointer
void SetInputImage3(const TInput *image)
Classify each voxels into one of the given GMM classes.
itk::ImageRegionConstIterator< TInput > InputConstIteratorType
void SetGaussianModel(std::vector< GaussianFunctionType::Pointer > &model)
std::vector< GaussianFunctionType::Pointer > GetGaussiabModel()