ANIMA  4.0
animaGraph3DFilter.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "animaNLinksFilter.h"
4 
5 #include <itkImageToImageFilter.h>
6 #include <itkImageRegionIterator.h>
7 #include <itkImageRegionConstIterator.h>
8 #include <itkVariableSizeMatrix.h>
9 #include <itkBinaryBallStructuringElement.h>
10 #include <itkGrayscaleDilateImageFilter.h>
11 #include <itkResampleImageFilter.h>
12 #include <itkIdentityTransform.h>
13 #include <itkBSplineInterpolateImageFunction.h>
14 #include <itkMaskImageFilter.h>
15 
16 namespace anima
17 {
22 template <typename TInput, typename TOutput>
24  public itk::ImageToImageFilter< TInput , TOutput >
25 {
26 public:
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(Graph3DFilter, ImageToImageFilter)
38 
39 
40  typedef typename TInput::Pointer InputImagePointer;
41  typedef typename TInput::ConstPointer InputImageConstPointer;
42  typedef itk::ImageRegionConstIterator< TInput > InRegionConstIteratorType;
43  typedef itk::ImageRegionIterator< TInput > InRegionIteratorType;
44  typedef typename TInput::PixelType InputPixelType;
45 
46  typedef double PixelTypeD;
47  typedef itk::Image <PixelTypeD,3> TSeedProba;
48  typedef TSeedProba::Pointer ImagePointerProba;
49  typedef itk::ImageRegionIterator <TSeedProba> ImageIteratorTypeProba;
50  typedef TSeedProba::PixelType SeedProbaPixelType;
51 
52  typedef typename TOutput::Pointer OutputImagePointer;
53  typedef typename TOutput::PixelType OutputPixelType;
54  typedef typename itk::ImageRegionIterator < TOutput > OutputIteratorType;
55 
56  typedef unsigned char PixelTypeUC;
57  typedef itk::Image <PixelTypeUC,3> TMask;
58  typedef TMask::Pointer TMaskPointer;
59  typedef itk::ImageRegionIterator< TMask > MaskRegionIteratorType;
60  typedef itk::ImageRegionConstIterator< TMask > MaskRegionConstIteratorType;
61 
62  typedef Graph<double,double,double> GraphType;
63 
64  typedef double NumericType;
65  typedef itk::VariableSizeMatrix<NumericType> doubleVariableSizeMatrixType;
66 
67  typedef itk::IdentityTransform<double, 3> TransformType;
68  typedef itk::ResampleImageFilter<TInput, TInput> ResampleImageFilterType;
70  typedef itk::ResampleImageFilter<TSeedProba, TSeedProba> ResampleImageFilterdoubleType;
71 
73  void SetInputImage(unsigned int i, const TInput* image);
74 
77  void SetMask(const TMask* mask);
78 
81  void SetInputSeedProbaSources(const TSeedProba* mask);
82  void SetInputSeedProbaSinks(const TSeedProba* mask);
83 
84  void SetMatFilename(std::string mat){m_MatFilename=mat;}
85  void SetMatrix(doubleVariableSizeMatrixType mat){m_Matrix=mat;}
86 
89 
90  TMask::Pointer Upsample(const TMask* input, TMask::SizeType upSize, TMask::DirectionType outputDirection, TMask::PointType outputOrigin);
91  TMask::Pointer Dilate(const TMask* input, const TMask* mask);
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(Verbose, bool)
110  itkGetMacro(Verbose, bool)
111 
112 protected:
113 
117  typename ResampleImageFilterType::Pointer m_Resample1;
118  typename ResampleImageFilterType::Pointer m_Resample2;
119  typename ResampleImageFilterType::Pointer m_Resample3;
120  typename ResampleImageFilterType::Pointer m_Resample4;
121  typename ResampleImageFilterType::Pointer m_Resample5;
122  ResampleImageFilterMaskType::Pointer m_ResampleMask;
123  ResampleImageFilterdoubleType::Pointer m_ResampleSources;
124  ResampleImageFilterdoubleType::Pointer m_ResampleSinks;
125 
127  {
128  this->SetNthOutput( 0, this->MakeOutput(0) );
129  this->SetNthOutput( 1, this->MakeOutput(1) );
130 
131  m_Sigma = 0.6;
132  m_UseSpectralGradient=true;
133  m_Verbose=false;
134  m_NbInputs = 4;
135  m_NbMaxImages = 10;
136  m_IndexImage1=m_NbMaxImages,m_IndexImage2=m_NbMaxImages,m_IndexImage3=m_NbMaxImages, m_IndexImage4=m_NbMaxImages,m_IndexImage5=m_NbMaxImages, m_IndexImage6=m_NbMaxImages;
137 
138  m_NLinksFilter = NLinksFilterType::New();
139 
140  m_Tol = 0.0001;
141 
142  this->SetNumberOfRequiredOutputs(2);
143  this->SetNumberOfRequiredInputs(4);
144  }
145 
146  virtual ~Graph3DFilter()
147  {
148  }
149 
151  itk::DataObject::Pointer MakeOutput(unsigned int idx);
152 
153  typename TInput::ConstPointer GetInputImage1();
154  typename TInput::ConstPointer GetInputImage2();
155  typename TInput::ConstPointer GetInputImage3();
156  typename TInput::ConstPointer GetInputImage4();
157  typename TInput::ConstPointer GetInputImage5();
158 
159  TMask::ConstPointer GetMask();
160 
161  TSeedProba::ConstPointer GetInputSeedProbaSources();
162  TSeedProba::ConstPointer GetInputSeedProbaSinks();
163 
164  doubleVariableSizeMatrixType GetMatrix(void){return m_Matrix;}
165  std::string GetMatFilename(void){return m_MatFilename;}
166 
167  void GenerateData() ITK_OVERRIDE;
168  bool CheckMemory();
169  void ProcessGraphCut();
170  void FindDownsampleFactor();
171  void InitResampleFilters();
172  void ProcessDownsampledGraphCut(int current_count);
173 
174 private:
175  ITK_DISALLOW_COPY_AND_ASSIGN(Graph3DFilter);
176 
179  bool m_UseSpectralGradient;
180 
183  double m_Sigma;
184 
187  GraphType *m_graph;
188 
191  std::string m_MatFilename;
193 
194  bool m_Verbose;
195 
196  unsigned int m_NbInputs;
197  unsigned int m_IndexImage1, m_IndexImage2, m_IndexImage3, m_IndexImage4,m_IndexImage5, m_IndexImage6, m_NbMaxImages;
198 
199  double m_Tol;
200 
201  double m_DownsamplingFactor;
202  int m_Count;
203 
204  TMask::Pointer m_CurrentMask;
205  typename TInput::SizeType m_InputSize;
206  typename TInput::DirectionType m_OutputDirection;
207  typename TInput::PointType m_OutputOrigin;
208 };
209 
210 } // end of namespace anima
211 
212 #include "animaGraph3DFilter.hxx"
TSeedProba::ConstPointer GetInputSeedProbaSinks()
Class creating a 3D graph in a graph cut framework.
ResampleImageFilterType::Pointer m_Resample3
TSeedProba::Pointer ImagePointerProba
ResampleImageFilterdoubleType::Pointer m_ResampleSinks
itk::ResampleImageFilter< TMask, TMask > ResampleImageFilterMaskType
itk::ImageRegionConstIterator< TInput > InRegionConstIteratorType
itk::ImageRegionIterator< TOutput > OutputIteratorType
NLinksFilterType::Pointer m_NLinksFilterDecim
NLinksFilterType::Pointer m_NLinksFilter
STL namespace.
std::string GetMatFilename(void)
TSeedProba::ConstPointer GetInputSeedProbaSources()
void SetInputSeedProbaSources(const TSeedProba *mask)
TOutput::PixelType OutputPixelType
ResampleImageFilterType::Pointer m_Resample2
Class allowing the decimation of the images if necessary (if 3D graph size causes memory problems)...
itk::VariableSizeMatrix< NumericType > doubleVariableSizeMatrixType
doubleVariableSizeMatrixType GetMatrix(void)
void SetTol(const double tol)
TInput::ConstPointer InputImageConstPointer
TMask::Pointer TMaskPointer
OutputImagePointer GetOutputBackground()
ResampleImageFilterType::Pointer m_Resample1
NLinksFilter< TInput, TMask > NLinksFilterType
itk::Image< PixelTypeUC, 3 > TMask
void SetMask(const TMask *mask)
void SetInputSeedProbaSinks(const TSeedProba *mask)
itk::ResampleImageFilter< TInput, TInput > ResampleImageFilterType
itk::ResampleImageFilter< TSeedProba, TSeedProba > ResampleImageFilterdoubleType
TInput::PixelType InputPixelType
itk::IdentityTransform< double, 3 > TransformType
static Pointer New()
TMask::Pointer Dilate(const TMask *input, const TMask *mask)
TInput::Pointer InputImagePointer
TMask::ConstPointer GetMask()
itk::ImageRegionIterator< TInput > InRegionIteratorType
void SetMatFilename(std::string mat)
itk::ImageRegionConstIterator< TMask > MaskRegionConstIteratorType
TInput::ConstPointer GetInputImage4()
void ProcessDownsampledGraphCut(int current_count)
ResampleImageFilterdoubleType::Pointer m_ResampleSources
void GenerateData() ITK_OVERRIDE
Superclass::OutputImageRegionType OutputImageRegionType
TInput::ConstPointer GetInputImage2()
itk::DataObject::Pointer MakeOutput(unsigned int idx)
ResampleImageFilterType::Pointer m_Resample5
void SetMatrix(doubleVariableSizeMatrixType mat)
TInput::ConstPointer GetInputImage3()
TMask::Pointer Upsample(const TMask *input, TMask::SizeType upSize, TMask::DirectionType outputDirection, TMask::PointType outputOrigin)
itk::ImageToImageFilter< TInput, TOutput > Superclass
itk::ImageRegionIterator< TSeedProba > ImageIteratorTypeProba
TOutput::Pointer OutputImagePointer
ResampleImageFilterType::Pointer m_Resample4
itk::SmartPointer< Self > Pointer
itk::SmartPointer< const Self > ConstPointer
void SetInputImage(unsigned int i, const TInput *image)
itk::Image< PixelTypeD, 3 > TSeedProba
ResampleImageFilterMaskType::Pointer m_ResampleMask
TInput::ConstPointer GetInputImage1()
TInput::ConstPointer GetInputImage5()
TSeedProba::PixelType SeedProbaPixelType
itk::SmartPointer< Self > Pointer
itk::ImageRegionIterator< TMask > MaskRegionIteratorType
OutputImagePointer GetOutput()