ANIMA  4.0
animaNLinksFilter.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 <itkVariableSizeMatrix.h>
7 #include <itkCSVArray2DFileReader.h>
8 #include "animaGraph.h"
9 
10 namespace anima
11 {
22 template <typename TInput, typename TOutput>
23 class NLinksFilter :
24  public itk::ImageToImageFilter< TInput , TOutput >
25 {
26 public:
28  typedef NLinksFilter Self;
29  typedef itk::ImageToImageFilter< TInput , TOutput> Superclass;
30  typedef itk::SmartPointer<Self> Pointer;
31  typedef itk::SmartPointer<const Self> ConstPointer;
32 
34  itkNewMacro(Self)
35 
36 
37  itkTypeMacro(NLinksFilter, ImageToImageFilter)
38 
39 
40  typedef typename TInput::Pointer InputImagePointer;
41  typedef typename TInput::ConstPointer InputImageConstPointer;
42  typedef itk::ImageRegionConstIterator< TInput > InRegionConstIteratorType;
43  typedef typename TInput::PixelType InputPixelType;
44 
45  typedef typename TOutput::Pointer OutputImagePointer;
46  typedef typename TOutput::PixelType OutputPixelType;
47  typedef typename itk::ImageRegionIterator < TOutput > OutputIteratorType;
48 
49  typedef double PixelTypeD;
50  typedef itk::Image <PixelTypeD,3> TSeedProba;
51  typedef TSeedProba::Pointer ImagePointerProba;
52  typedef itk::ImageRegionIterator <TSeedProba> ImageIteratorTypeProba;
53  typedef TSeedProba::PixelType SeedProbaPixelType;
54 
55  typedef int PixelTypeInt;
56  typedef itk::Image <PixelTypeInt,3> ImageTypeInt;
57  typedef ImageTypeInt::IndexType pixelIndexInt;
58  typedef itk::ImageRegionIterator <ImageTypeInt> ImageIteratorTypeInt;
59 
60  typedef unsigned char PixelTypeUC;
61  typedef itk::Image <PixelTypeUC,3> TMask;
62  typedef TMask::Pointer TMaskPointer;
63  typedef itk::ImageRegionIterator< TMask > MaskRegionIteratorType;
64  typedef itk::ImageRegionConstIterator< TMask > MaskRegionConstIteratorType;
65 
66  typedef Graph<double,double,double> GraphType;
67 
68  typedef double NumericType;
69  typedef itk::VariableSizeMatrix<NumericType> doubleVariableSizeMatrixType;
70 
72  void SetInputImage1(const TInput* image);
73  void SetInputImage2(const TInput* image);
74  void SetInputImage3(const TInput* image);
75  void SetInputImage4(const TInput* image);
76  void SetInputImage5(const TInput* image);
77 
80  void SetMask(const TMask* mask);
81 
84  void SetInputSeedProbaSources(const TSeedProba* mask);
85  void SetInputSeedProbaSinks(const TSeedProba* mask);
86 
87  void SetMatFilename(std::string mat){m_MatFilename=mat;}
88  void SetMatrix(doubleVariableSizeMatrixType mat){m_Matrix=mat;}
89 
92 
94  typedef typename Superclass::OutputImageRegionType OutputImageRegionType;
95 
96  void SetTol(const double tol)
97  {
98  this->SetCoordinateTolerance(tol);
99  this->SetDirectionTolerance(tol);
100  m_Tol = tol;
101  }
102 
103  itkSetMacro(Sigma, double)
104  itkGetMacro(Sigma, double)
105 
106  itkSetMacro(UseSpectralGradient, bool)
107  itkGetMacro(UseSpectralGradient, bool)
108 
109  itkSetMacro(NbModalities, unsigned int)
110  itkGetMacro(NbModalities, unsigned int)
111 
112  itkSetMacro(Verbose, bool)
113  itkGetMacro(Verbose, bool)
114 
115 protected:
117  {
118  this->SetNthOutput( 0, this->MakeOutput(0) );
119  this->SetNthOutput( 1, this->MakeOutput(1) );
120 
121  m_Sigma = 0.6;
122  m_UseSpectralGradient=true;
123  m_Verbose=false;
124  m_NbModalities = 0;
125  m_NbInputs = 4;
126  m_NbMaxImage = 10;
127  m_IndexImage1=m_NbMaxImage,m_IndexImage2=m_NbMaxImage,m_IndexImage3=m_NbMaxImage, m_IndexImage4=m_NbMaxImage,m_IndexImage5=m_NbMaxImage;
128 
129  m_Tol = 0.0001;
130 
131  this->SetNumberOfRequiredOutputs(2);
132  this->SetNumberOfRequiredInputs(4);
133  }
134 
135  virtual ~NLinksFilter()
136  {
137  }
138 
140  itk::DataObject::Pointer MakeOutput(unsigned int idx);
141 
142  typename TInput::ConstPointer GetInputImage1();
143  typename TInput::ConstPointer GetInputImage2();
144  typename TInput::ConstPointer GetInputImage3();
145  typename TInput::ConstPointer GetInputImage4();
146  typename TInput::ConstPointer GetInputImage5();
147  typename TInput::ConstPointer GetInputImage6();
148 
149  TMask::ConstPointer GetMask();
150 
151  TSeedProba::ConstPointer GetInputSeedProbaSources();
152  TSeedProba::ConstPointer GetInputSeedProbaSinks();
153 
154  doubleVariableSizeMatrixType GetMatrix(void){return m_Matrix;}
155  std::string GetMatFilename(void){return m_MatFilename;}
156 
157  bool readMatrixFile();
158 
159  void CheckSpectralGradient(void);
160  void GenerateData() ITK_OVERRIDE;
161  void SetGraph();
162  bool isInside (unsigned int x,unsigned int y,unsigned int z ) const;
163  void CreateGraph();
164  double computeNLink(int i1, int j1, int k1, int i2, int j2, int k2);
165 
166 private:
167  ITK_DISALLOW_COPY_AND_ASSIGN(NLinksFilter);
168 
171  bool m_UseSpectralGradient;
172 
175  double m_Sigma;
176 
179  GraphType *m_graph;
180 
183  std::string m_MatFilename;
185 
186  typename TOutput::SizeType m_size;
187 
190  std::vector<InputImageConstPointer > m_ListImages;
191 
192  bool m_Verbose;
193 
194  ImageTypeInt::Pointer pix;
195 
198  TSeedProba::Pointer m_e1, m_e2; // Precomputed spectral grad quantities (keep track of 2 images instead of 3...
199  unsigned int m_NbModalities;
200  unsigned int m_NbInputs, m_NbMaxImage;
201  unsigned int m_IndexImage1, m_IndexImage2, m_IndexImage3, m_IndexImage4,m_IndexImage5;
202 
203  double m_Tol;
204 };
205 
206 } // end of namespace anima
207 
208 #include "animaNLinksFilter.hxx"
TInput::ConstPointer GetInputImage2()
Class creating a 3D graph in a graph cut framework.
doubleVariableSizeMatrixType GetMatrix(void)
itk::ImageRegionIterator< TSeedProba > ImageIteratorTypeProba
TInput::ConstPointer GetInputImage1()
itk::VariableSizeMatrix< NumericType > doubleVariableSizeMatrixType
itk::Image< PixelTypeD, 3 > TSeedProba
TMask::Pointer TMaskPointer
void SetMatrix(doubleVariableSizeMatrixType mat)
TOutput::PixelType OutputPixelType
unsigned char PixelTypeUC
OutputImagePointer GetOutput()
TOutput::Pointer OutputImagePointer
STL namespace.
TSeedProba::ConstPointer GetInputSeedProbaSinks()
itk::SmartPointer< const Self > ConstPointer
itk::ImageRegionIterator< TMask > MaskRegionIteratorType
void SetInputImage4(const TInput *image)
ImageTypeInt::IndexType pixelIndexInt
void GenerateData() ITK_OVERRIDE
void SetTol(const double tol)
TInput::ConstPointer GetInputImage6()
void SetMatFilename(std::string mat)
void SetMask(const TMask *mask)
TInput::Pointer InputImagePointer
itk::Image< PixelTypeInt, 3 > ImageTypeInt
TMask::ConstPointer GetMask()
itk::ImageRegionConstIterator< TInput > InRegionConstIteratorType
void SetInputSeedProbaSinks(const TSeedProba *mask)
TInput::ConstPointer GetInputImage5()
TInput::ConstPointer InputImageConstPointer
TSeedProba::ConstPointer GetInputSeedProbaSources()
TInput::ConstPointer GetInputImage3()
void SetInputImage5(const TInput *image)
itk::ImageRegionIterator< TOutput > OutputIteratorType
void SetInputImage2(const TInput *image)
itk::ImageRegionIterator< ImageTypeInt > ImageIteratorTypeInt
double computeNLink(int i1, int j1, int k1, int i2, int j2, int k2)
itk::ImageRegionConstIterator< TMask > MaskRegionConstIteratorType
itk::Image< PixelTypeUC, 3 > TMask
itk::ImageToImageFilter< TInput, TOutput > Superclass
std::string GetMatFilename(void)
itk::SmartPointer< Self > Pointer
TInput::ConstPointer GetInputImage4()
TSeedProba::PixelType SeedProbaPixelType
Superclass::OutputImageRegionType OutputImageRegionType
void SetInputImage1(const TInput *image)
bool isInside(unsigned int x, unsigned int y, unsigned int z) const
itk::DataObject::Pointer MakeOutput(unsigned int idx)
TSeedProba::Pointer ImagePointerProba
OutputImagePointer GetOutputBackground()
void SetInputSeedProbaSources(const TSeedProba *mask)
TInput::PixelType InputPixelType
void SetInputImage3(const TInput *image)