Slicer  4.8
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
itkGrowCutSegmentationImageFilter.h
Go to the documentation of this file.
1 #ifndef itkGrowCutSegmentationImageFilter_h
2 #define itkGrowCutSegmentationImageFilter_h
3 
4 #include "itkImage.h"
5 #include "itkImageToImageFilter.h"
6 #include "itkSimpleDataObjectDecorator.h"
7 #include "itkVectorContainer.h"
8 //#include "itkCommand.h"
9 
10 //#include "itkGrowCutSegmentationUpdateFilter.h"
11 
12 #include <vcl_compiler.h>
13 
14 #include <iostream>
15 #include <list>
16 #include <vector>
17 
18 #ifndef PixelState
20  UNLABELED = 0,
21  LABELED = 1,
23  SATURATED = 3 };
24 #endif
25 
26 namespace itk
27 {
28 
54 /* template<class TInputImage, */
55 /* class TOutputImage, class TLabelPixelType = short, */
56 /* class TWeightPixelType = float > */
57 template<class TInputImage,
58  class TOutputImage,
59  class TWeightPixelType = float>
60  class GrowCutSegmentationImageFilter: public ImageToImageFilter<TInputImage,TOutputImage>
61 {
62 
63  public:
66  typedef ImageToImageFilter<TInputImage,TOutputImage> Superclass;
67  typedef SmartPointer<Self> Pointer;
68  typedef SmartPointer<const Self> ConstPointer;
69 
71  itkNewMacro(Self);
72 
75  ImageToImageFilter);
76 
78  itkStaticConstMacro(ImageDimension, unsigned int,
79  TInputImage::ImageDimension );
80 
81  typedef TInputImage InputImageType;
82  typedef typename InputImageType::Pointer InputImagePointer;
83  typedef typename InputImageType::ConstPointer InputImageConstPointer;
84 
85  typedef typename InputImageType::PixelType InputPixelType;
86  typedef typename InputImageType::IndexType InputIndexType;
87  typedef typename InputImageType::SizeType SizeType;
88 
89  typedef TOutputImage OutputImageType;
90  typedef typename OutputImageType::Pointer OutputImagePointer;
91  typedef typename OutputImageType::RegionType OutputImageRegionType;
92  typedef typename OutputImageType::PixelType OutputPixelType;
93  typedef typename OutputImageType::IndexType OutputIndexType;
94  typedef typename InputImageType::SizeType OutputSizeType;
95 
96 
98  typedef typename DataObject::Pointer DataObjectPointer;
99 
100 
102  itkStaticConstMacro(InputImageDimension, unsigned int,
103  TInputImage::ImageDimension);
104  itkStaticConstMacro(OutputImageDimension, unsigned int,
105  TOutputImage::ImageDimension);
106 
108  typedef Index<itkGetStaticConstMacro(InputImageDimension)> IndexType;
109 
111  typedef typename InputImageType::SizeType InputSizeType;
112 
113  /* NodeContainer typedef support for storing a set of seed points */
114  typedef VectorContainer<unsigned int, IndexType> NodeContainer;
115 
116  /* NodeContainer pointer support */
117  typedef typename NodeContainer::Pointer NodeContainerPointer;
118 
124 
125 
127  /* indicates the strength of a label for a given cell */
128  typedef Image<TWeightPixelType, itkGetStaticConstMacro(InputImageDimension) > WeightImageType;
129 
131  typedef typename WeightImageType::Pointer WeightImagePointer;
132 
133  typedef TWeightPixelType WeightPixelType;
134 
136  void SetInputImage( const InputImageType *in)
137  {
138  this->ProcessObject::SetNthInput(0, const_cast< InputImageType *>(in) );
139  }
140 
141  const InputImagePointer GetInputImage( );
142 
144  void SetLabelImage( const OutputImageType *f)
145  {
146  this->ProcessObject::SetNthInput(1, const_cast< OutputImageType *>(f) );
147  m_LabelImage = static_cast< OutputImageType *>(this->ProcessObject::GetInput(1));
148  }
149 
150  const OutputImagePointer GetLabelImage();
151 
153  const WeightImagePointer GetStrengthImage();
154 
156  void SetStrengthImage( const WeightImageType *w )
157  {
158  this->ProcessObject::SetNthInput(2,const_cast< WeightImageType *>(w));
159  //m_WeightImage = static_cast< WeightImageType *>(this->ProcessObject::GetInput(2));
160  }
161 
162  const WeightImagePointer GetUpdatedStrengthImage();
163 
165  void SetStateImage( const OutputImageType *l);
166  const OutputImagePointer GetStateImage();
167 
168  void SetDistancesImage( const WeightImageType *d);
169  const WeightImagePointer GetDistancesImage();
170 
171  void SetMaxSaturationImage( const WeightImageType *w);
172  const WeightImagePointer GetMaxSaturationImage();
173 
175  itkSetMacro( SeedStrength, double );
176 
178  itkGetConstMacro( SeedStrength, double );
179 
181  itkSetMacro( Labeled, unsigned int);
182  itkGetMacro( Labeled, unsigned int);
183 
185  itkSetMacro( LocallySaturated, unsigned int);
186  itkGetMacro( LocallySaturated, unsigned int);
187 
189  itkSetMacro( Saturated, unsigned int);
190  itkGetMacro( Saturated, unsigned int);
191 
193  itkSetMacro( MaxIterations, unsigned int );
194 
196  itkGetConstMacro( MaxIterations, unsigned int );
197 
199  itkSetMacro( ObjectRadius, unsigned int );
200 
202  itkGetConstMacro( ObjectRadius, unsigned int );
203 
205  void SetROIStart( const OutputIndexType &start)
206  {
207  m_RoiStart = start;
208  }
209 
210  OutputIndexType GetROIStart() const
211  {
212  return m_RoiStart;
213  }
214 
215 
216  void SetROIEnd(const OutputIndexType &end)
217  {
218  m_RoiEnd = end;
219  }
220 
221 
222  OutputIndexType GetROIEnd() const
223  {
224  return m_RoiEnd;
225  }
226 
228  itkSetMacro( Radius, InputSizeType );
229 
231  itkGetConstMacro( Radius, InputSizeType );
232 
236  itkSetMacro(RunOneIteration, bool);
237  itkGetConstMacro(RunOneIteration, bool);
238  itkBooleanMacro(RunOneIteration);
239 
240 
245  itkSetMacro(SetDistancesImage, bool);
246  itkGetConstMacro(SetDistancesImage, bool);
247  itkBooleanMacro(SetDistancesImage);
248 
253  itkSetMacro(SetStateImage, bool);
254  itkGetConstMacro(SetStateImage, bool);
255  itkBooleanMacro(SetStateImage);
256 
261  itkSetMacro(SetMaxSaturationImage, bool);
262  itkGetConstMacro(SetMaxSaturationImage, bool);
263  itkBooleanMacro(SetMaxSaturationImage);
264 
265  protected:
266 
269 
270  // Override since the filter needs all the data for the algorithm
271  void GenerateInputRequestedRegion() ITK_OVERRIDE;
272 
273  // Override since the filter produces the entire dataset
274  void EnlargeOutputRequestedRegion(DataObject *output) ITK_OVERRIDE;
275 
276  void GenerateData() ITK_OVERRIDE;
277 
278  void ThreadedGenerateData( const OutputImageRegionType &outputRegionForThread ,
279  ThreadIdType threadId ) ITK_OVERRIDE;
280 
281  void AfterThreadedGenerateData() ITK_OVERRIDE;
282 
283  void Initialize(OutputImageType* output);
284 
285  void PrintSelf ( std::ostream& os, Indent indent ) const ITK_OVERRIDE;
286 
287  void GrowCutSlowROI( TOutputImage *);
288 
289 
290  private:
291 
292  GrowCutSegmentationImageFilter(const Self&); //purposely not implemented
293  void operator=(const Self&); // purposely not implemented
294 
295  bool InitializeStateImage( OutputImageType *state );
296 
297  void InitializeDistancesImage(TInputImage *input,WeightImageType *distance);
298 
299  void GetRegionOfInterest();
300 
301  void ComputeLabelVolumes(TOutputImage *outputImage, std::vector< unsigned > &volumes, std::vector< unsigned > &phyVolumes);
302 
303  void MaskSegmentedImageByWeight(float upperThresh);
304 
305 
306  WeightPixelType m_ConfThresh;
307  InputSizeType m_Radius;
308  OutputImagePointer m_LabelImage;
309  WeightImagePointer m_WeightImage;
310  unsigned int m_Labeled;
311  unsigned int m_LocallySaturated;
312  unsigned int m_Saturated;
313 
314  double m_SeedStrength;
315  bool m_RunOneIteration;
316  bool m_SetStateImage;
317  bool m_SetDistancesImage;
318  bool m_SetMaxSaturationImage;
319 
320  unsigned int m_MaxIterations;
321  unsigned int m_ObjectRadius;
322 
323  OutputPixelType m_ObjectLabel;
324  OutputPixelType m_BackgroundLabel;
325  OutputPixelType m_UnknownLabel;
326 
327  OutputIndexType m_RoiStart;
328  OutputIndexType m_RoiEnd;
329 
330 };
331 
332 } // namespace itk
333 
334 
335 #ifndef ITK_MANUAL_INSTANTIATION
336 #include "itkGrowCutSegmentationImageFilter.txx"
337 #endif
338 
339 #endif
void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, ThreadIdType threadId) ITK_OVERRIDE
void GenerateInputRequestedRegion() ITK_OVERRIDE
const WeightImagePointer GetStrengthImage()
void SetStateImage(const OutputImageType *l)
Simplified inverse ITK transforms.
const OutputImagePointer GetLabelImage()
Image< TWeightPixelType, itkGetStaticConstMacro(InputImageDimension) > WeightImageType
const WeightImagePointer GetMaxSaturationImage()
const InputImagePointer GetInputImage()
itkStaticConstMacro(ImageDimension, unsigned int, TInputImage::ImageDimension)
itkGetMacro(Labeled, unsigned int)
void SetMaxSaturationImage(const WeightImageType *w)
void GrowCutSlowROI(TOutputImage *)
itkGetConstMacro(SeedStrength, double)
itkTypeMacro(GrowCutSegmentationImageFilter, ImageToImageFilter)
ImageToImageFilter< TInputImage, TOutputImage > Superclass
void AfterThreadedGenerateData() ITK_OVERRIDE
Index< itkGetStaticConstMacro(InputImageDimension)> IndexType
const OutputImagePointer GetStateImage()
void PrintSelf(std::ostream &os, Indent indent) const ITK_OVERRIDE
const WeightImagePointer GetDistancesImage()
VectorContainer< unsigned int, IndexType > NodeContainer
void EnlargeOutputRequestedRegion(DataObject *output) ITK_OVERRIDE
const WeightImagePointer GetUpdatedStrengthImage()
void SetROIStart(const OutputIndexType &start)
void SetDistancesImage(const WeightImageType *d)
void Initialize(OutputImageType *output)
itkSetMacro(SeedStrength, double)