ANIMA  4.0
animaRemoveTouchingBorderFilter.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 <itkLabelImageToLabelMapFilter.h>
7 #include <itkLabelMapToLabelImageFilter.h>
8 #include <itkLabelContourImageFilter.h>
9 #include <itkConnectedComponentImageFilter.h>
11 #include <itkMultiThreaderBase.h>
12 
13 namespace anima
14 {
21 template<typename TInput, typename TMask, typename TOutput>
23  public itk::ImageToImageFilter< TInput , TOutput >
24 {
25 public:
28  typedef itk::ImageToImageFilter< TInput , TOutput > Superclass;
29  typedef itk::SmartPointer<Self> Pointer;
30  typedef itk::SmartPointer<const Self> ConstPointer;
31 
33  itkNewMacro(Self)
34 
35 
36  itkTypeMacro(RemoveTouchingBorderFilter, ImageToImageFilter)
37 
38 
41  typedef TInput InputImageType;
42  typedef typename InputImageType::Pointer InputImagePointer;
43  typedef typename itk::ImageRegionIterator< InputImageType > InputIteratorType;
44  typedef typename itk::ImageRegionConstIterator< InputImageType > InputConstIteratorType;
45 
47  typedef TMask MaskImageType;
48  typedef typename MaskImageType::Pointer MaskImagePointer;
49  typedef typename itk::ImageRegionIterator< MaskImageType > MaskIteratorType;
50  typedef typename itk::ImageRegionConstIterator< MaskImageType > MaskConstIteratorType;
51 
53  typedef TOutput OutputImageType;
54  typedef typename OutputImageType::Pointer OutputImagePointer;
55  typedef typename itk::ImageRegionIterator< OutputImageType > OutputIteratorType;
56 
57  typedef unsigned int PixelTypeInt;
58  typedef itk::Image <PixelTypeInt,3> ImageTypeInt;
59  typedef itk::ImageRegionIterator< ImageTypeInt > ImageIteratorTypeInt;
60 
61  typedef itk::LabelImageToLabelMapFilter<ImageTypeInt> LabelImageToLabelMapFilterType;
62  typedef typename LabelImageToLabelMapFilterType::OutputImageType TOutputMap;
63  typedef itk::LabelImageToLabelMapFilter<TInput,TOutputMap> LabelImageToLabelMapFilterType2;
64 
65  typedef itk::LabelMapToLabelImageFilter<TOutputMap, ImageTypeInt> LabelMapToLabelImageFilterType;
66 
67  typedef itk::ConnectedComponentImageFilter <InputImageType,ImageTypeInt> ConnectedComponentImageFilterType;
68  typedef itk::ConnectedComponentImageFilter <TMask, ImageTypeInt > ConnectedComponentImageFilterType2;
69 
70  typedef itk::LabelContourImageFilter<ImageTypeInt, ImageTypeInt> LabelContourImageFilterType;
71 
73  void SetInputImageSeg(const TInput* image);
74 
75  void SetOutputNonTouchingBorderFilename(std::string fn){m_OutputNonTouchingBorderFilename = fn;}
76  void SetOutputTouchingBorderFilename(std::string fn){m_OutputTouchingBorderFilename = fn;}
77 
79  void SetMask(const TMask* mask);
80 
81  TOutput* GetOutputTouchingBorder();
82  TOutput* GetOutputNonTouchingBorder();
83 
84  void WriteOutputs();
85 
86  void SetTol(const double tol)
87  {
88  this->SetCoordinateTolerance(tol);
89  this->SetDirectionTolerance(tol);
90  m_Tol = tol;
91  }
92 
94  typedef typename Superclass::OutputImageRegionType OutputImageRegionType;
95 
96  itkSetMacro(NoContour, bool)
97  itkGetMacro(NoContour, bool)
98 
99  itkSetMacro(LabeledImage, bool)
100  itkGetMacro(LabeledImage, bool)
101 
102  itkSetMacro(Verbose, bool)
103  itkGetMacro(Verbose, bool)
104 
105 protected:
107  {
108  this->SetNumberOfRequiredOutputs(2);
109  this->SetNumberOfRequiredInputs(2);
110 
111  this->SetNthOutput( 0, this->MakeOutput(0) );
112  this->SetNthOutput( 1, this->MakeOutput(1) );
113 
114  m_LabeledImage=false;
115  m_NoContour=false;
116  m_Verbose=false;
117  m_Tol = 0.0001;
118  this->SetNumberOfWorkUnits(itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads());
119  }
120 
122  {
123  }
124 
126  itk::DataObject::Pointer MakeOutput(unsigned int idx);
127 
128  typename TInput::ConstPointer GetInputImageSeg();
129  typename TMask::ConstPointer GetMask();
130 
132  virtual void GenerateData() ITK_OVERRIDE;
133 
134 private:
135  ITK_DISALLOW_COPY_AND_ASSIGN(RemoveTouchingBorderFilter);
136 
137  bool m_LabeledImage;
138  bool m_NoContour;
139  bool m_Verbose;
140 
141  std::string m_OutputNonTouchingBorderFilename;
142  std::string m_OutputTouchingBorderFilename;
143 
144  std::vector<int> m_labelsToRemove;
145 
146  double m_Tol;
147 };
148 
149 } // end of namespace anima
150 
itk::LabelContourImageFilter< ImageTypeInt, ImageTypeInt > LabelContourImageFilterType
Class selecting the connected components touching a given mask border. In MRI, external CSF may conta...
itk::ImageRegionIterator< OutputImageType > OutputIteratorType
STL namespace.
Superclass::OutputImageRegionType OutputImageRegionType
itk::ImageRegionIterator< MaskImageType > MaskIteratorType
itk::ImageRegionConstIterator< InputImageType > InputConstIteratorType
itk::ImageToImageFilter< TInput, TOutput > Superclass
itk::ImageRegionIterator< ImageTypeInt > ImageIteratorTypeInt
itk::ConnectedComponentImageFilter< TMask, ImageTypeInt > ConnectedComponentImageFilterType2
LabelImageToLabelMapFilterType::OutputImageType TOutputMap
itk::LabelImageToLabelMapFilter< TInput, TOutputMap > LabelImageToLabelMapFilterType2
itk::LabelMapToLabelImageFilter< TOutputMap, ImageTypeInt > LabelMapToLabelImageFilterType
itk::ImageRegionIterator< InputImageType > InputIteratorType
itk::DataObject::Pointer MakeOutput(unsigned int idx)
itk::SmartPointer< const Self > ConstPointer
itk::ImageRegionConstIterator< MaskImageType > MaskConstIteratorType
itk::ConnectedComponentImageFilter< InputImageType, ImageTypeInt > ConnectedComponentImageFilterType
itk::LabelImageToLabelMapFilter< ImageTypeInt > LabelImageToLabelMapFilterType