ANIMA  4.0
animaGraphCutFilter.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <itkImageToImageFilter.h>
4 #include <itkVariableSizeMatrix.h>
6 #include "animaTLinksFilter.h"
7 #include "animaGraph3DFilter.h"
8 
9 namespace anima
10 {
16 template <typename TInput, typename TOutput>
18  public itk::ImageToImageFilter< TInput , TOutput >
19 {
20 public:
23  typedef itk::ImageToImageFilter< TInput , TOutput > Superclass;
24  typedef itk::SmartPointer<Self> Pointer;
25  typedef itk::SmartPointer<const Self> ConstPointer;
26 
28  itkNewMacro(Self);
29 
31  itkTypeMacro(GraphCutFilter, ImageToImageFilter);
32 
34  typedef typename TOutput::Pointer OutputImagePointer;
35 
36  typedef unsigned char PixelTypeUC;
37  typedef itk::Image <PixelTypeUC,3> TMask;
38  typedef TMask::Pointer TMaskPointer;
39 
40  typedef double PixelTypeD;
41  typedef itk::Image <PixelTypeD,3> TSeedProba;
42 
43  typedef double NumericType;
44  typedef itk::VariableSizeMatrix<NumericType> doubleVariableSizeMatrixType;
45 
47  void SetInputImage(unsigned int i, const TInput* image);
48 
51  void SetMask(const TMask* mask);
52 
55  void SetInputSeedSourcesMask(const TMask* mask);
56  void SetInputSeedSinksMask(const TMask* mask);
57 
58  void SetInputSeedSourcesProba(const TSeedProba* mask);
59  void SetInputSeedSinksProba(const TSeedProba* mask);
60 
61  void SetMatrix(doubleVariableSizeMatrixType mat){m_Matrix=mat;}
62  void SetMatrixGradFilename(std::string mat){m_MatrixGradFilename=mat;}
63 
64  std::string GetOutputFilename() {return m_OutputFilename;}
65  void SetOutputFilename(std::string filename) {m_OutputFilename=filename;}
66 
67  TLinkMode GetTLinkMode() {return m_TLinkMode;}
68  void SetTLinkMode(TLinkMode m) {m_TLinkMode=m;}
69 
70  OutputImagePointer GetOutput();
71  OutputImagePointer GetOutputBackground();
72 
73  void WriteOutputs();
74 
76  typedef typename Superclass::OutputImageRegionType OutputImageRegionType;
77 
78  void SetTol(const double tol)
79  {
80  this->SetCoordinateTolerance(tol);
81  this->SetDirectionTolerance(tol);
82  m_Tol = tol;
83  }
84 
85  itkSetMacro(Alpha, double)
86  itkGetMacro(Alpha, double)
87 
88  itkSetMacro(MultiVarSources, double)
89  itkGetMacro(MultiVarSources, double)
90 
91  itkSetMacro(MultiVarSinks, double)
92  itkGetMacro(MultiVarSinks, double)
93 
94  itkSetMacro(Sigma, double)
95  itkGetMacro(Sigma, double)
96 
97  itkSetMacro(UseSpectralGradient, bool)
98  itkGetMacro(UseSpectralGradient, bool)
99 
100  itkSetMacro(Verbose, bool)
101  itkGetMacro(Verbose, bool)
102 
103 protected:
106 
109 
111  {
112  this->SetNthOutput( 0, this->MakeOutput(0) );
113  this->SetNthOutput( 1, this->MakeOutput(1) );
114 
115  m_Alpha = 10;
116  m_MultiVarSources = 1;
117  m_MultiVarSinks = 1;
118  m_Sigma = 0.6;
119  m_UseSpectralGradient=true;
120  m_TLinkMode = singleGaussianTLink;
121  m_Verbose=false;
122  m_NbInputs = 2;
123  m_NbMaxImages = 12;
124  m_IndexSourcesMask = m_NbMaxImages, m_IndexSourcesProba = m_NbMaxImages,m_IndexSinksMask = m_NbMaxImages, m_IndexSinksProba = m_NbMaxImages,m_IndexMask= m_NbMaxImages;
125 
126  m_Tol = 0.0001;
127 
128  this->SetNumberOfRequiredOutputs(2);
129  this->SetNumberOfRequiredInputs(4);
130 
131  m_TLinksFilter = TLinksFilterType::New();
132 
133  m_Graph3DFilter = Graph3DFilterType::New();
134  m_Graph3DFilter->SetInputSeedProbaSources( m_TLinksFilter->GetOutputSources() );
135  m_Graph3DFilter->SetInputSeedProbaSinks( m_TLinksFilter->GetOutputSinks() );
136 
137  }
138 
139  virtual ~GraphCutFilter()
140  {
141  }
142 
144  itk::DataObject::Pointer MakeOutput(unsigned int idx);
145 
146  TMask::ConstPointer GetMask();
147 
148  TMask::ConstPointer GetInputSeedSourcesMask();
149  TMask::ConstPointer GetInputSeedSinksMask();
150 
151  TSeedProba::ConstPointer GetInputSeedSourcesProba();
152  TSeedProba::ConstPointer GetInputSeedSinksProba();
153 
154  doubleVariableSizeMatrixType GetMatrix(void){return m_Matrix;}
155  std::string GetMatrixGradFilename(void){return m_MatrixGradFilename;}
156 
157  void GenerateData() ITK_OVERRIDE;
158 
159 private:
160  ITK_DISALLOW_COPY_AND_ASSIGN(GraphCutFilter);
161 
164  bool m_UseSpectralGradient;
165 
168  double m_Sigma;
169 
172  double m_Alpha;
173 
174  double m_MultiVarSources;
175  double m_MultiVarSinks;
176 
177  TLinkMode m_TLinkMode;
178 
179  std::string m_OutputFilename;
180  std::string m_OutputBackgroundFilename;
181 
182  std::string m_MatrixGradFilename;
183  doubleVariableSizeMatrixType m_Matrix;
184 
185  bool m_Verbose;
186 
187  unsigned int m_NbInputs;
188  unsigned int m_NbModalities, m_NbMaxImages;
189  unsigned int m_IndexSourcesMask, m_IndexSourcesProba, m_IndexSinksMask, m_IndexSinksProba, m_IndexMask;
190 
191  double m_Tol;
192 };
193 
194 } // end of namespace anima
195 
196 #include "animaGraphCutFilter.hxx"
Graph3DFilterType::Pointer m_Graph3DFilter
void SetInputImage(unsigned int i, const TInput *image)
OutputImagePointer GetOutputBackground()
itk::Image< PixelTypeD, 3 > TSeedProba
TLinksFilterType::Pointer m_TLinksFilter
TMask::ConstPointer GetInputSeedSourcesMask()
void SetMatrixGradFilename(std::string mat)
std::string GetOutputFilename()
TLinkMode
Superclass::OutputImageRegionType OutputImageRegionType
itk::ImageToImageFilter< TInput, TOutput > Superclass
static Pointer New()
doubleVariableSizeMatrixType GetMatrix(void)
std::string GetMatrixGradFilename(void)
void GenerateData() ITK_OVERRIDE
TMask::ConstPointer GetInputSeedSinksMask()
Class allowing the decimation of the images if necessary (if 3D graph size causes memory problems)...
void SetInputSeedSinksProba(const TSeedProba *mask)
void SetMask(const TMask *mask)
Class computing the probability maps that are used to create the t-links.
void SetMatrix(doubleVariableSizeMatrixType mat)
itk::DataObject::Pointer MakeOutput(unsigned int idx)
itk::SmartPointer< Self > Pointer
itk::Image< PixelTypeUC, 3 > TMask
static Pointer New()
void SetOutputFilename(std::string filename)
itk::VariableSizeMatrix< NumericType > doubleVariableSizeMatrixType
OutputImagePointer GetOutput()
itk::SmartPointer< Self > Pointer
TOutput::Pointer OutputImagePointer
void SetInputSeedSourcesProba(const TSeedProba *mask)
TLinksFilter< TInput, TSeedProba > TLinksFilterType
void SetInputSeedSourcesMask(const TMask *mask)
Graph3DFilter< TInput, TOutput > Graph3DFilterType
itk::SmartPointer< const Self > ConstPointer
TMask::ConstPointer GetMask()
void SetTol(const double tol)
void SetInputSeedSinksMask(const TMask *mask)
Class performing grah cut segmentation. First the sources and sinks probabilities maps are computed u...
itk::SmartPointer< Self > Pointer
void SetTLinkMode(TLinkMode m)
TSeedProba::ConstPointer GetInputSeedSinksProba()
TSeedProba::ConstPointer GetInputSeedSourcesProba()