Slicer  4.10
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 <iostream>
13 #include <list>
14 #include <vector>
15 
16 #ifndef PixelState
18  UNLABELED = 0,
19  LABELED = 1,
21  SATURATED = 3 };
22 #endif
23 
24 namespace itk
25 {
26 
52 /* template<class TInputImage, */
53 /* class TOutputImage, class TLabelPixelType = short, */
54 /* class TWeightPixelType = float > */
55 template<class TInputImage,
56  class TOutputImage,
57  class TWeightPixelType = float>
58  class GrowCutSegmentationImageFilter: public ImageToImageFilter<TInputImage,TOutputImage>
59 {
60 
61  public:
64  typedef ImageToImageFilter<TInputImage,TOutputImage> Superclass;
65  typedef SmartPointer<Self> Pointer;
66  typedef SmartPointer<const Self> ConstPointer;
67 
70 
73  ImageToImageFilter);
74 
76  itkStaticConstMacro(ImageDimension, unsigned int,
77  TInputImage::ImageDimension );
78 
79  typedef TInputImage InputImageType;
80  typedef typename InputImageType::Pointer InputImagePointer;
81  typedef typename InputImageType::ConstPointer InputImageConstPointer;
82 
83  typedef typename InputImageType::PixelType InputPixelType;
84  typedef typename InputImageType::IndexType InputIndexType;
85  typedef typename InputImageType::SizeType SizeType;
86 
87  typedef TOutputImage OutputImageType;
88  typedef typename OutputImageType::Pointer OutputImagePointer;
89  typedef typename OutputImageType::RegionType OutputImageRegionType;
90  typedef typename OutputImageType::PixelType OutputPixelType;
91  typedef typename OutputImageType::IndexType OutputIndexType;
92  typedef typename InputImageType::SizeType OutputSizeType;
93 
94 
96  typedef typename DataObject::Pointer DataObjectPointer;
97 
98 
100  itkStaticConstMacro(InputImageDimension, unsigned int,
101  TInputImage::ImageDimension);
102  itkStaticConstMacro(OutputImageDimension, unsigned int,
103  TOutputImage::ImageDimension);
104 
106  typedef Index<itkGetStaticConstMacro(InputImageDimension)> IndexType;
107 
109  typedef typename InputImageType::SizeType InputSizeType;
110 
111  /* NodeContainer typedef support for storing a set of seed points */
112  typedef VectorContainer<unsigned int, IndexType> NodeContainer;
113 
114  /* NodeContainer pointer support */
115  typedef typename NodeContainer::Pointer NodeContainerPointer;
116 
122 
123 
125  /* indicates the strength of a label for a given cell */
126  typedef Image<TWeightPixelType, itkGetStaticConstMacro(InputImageDimension) > WeightImageType;
127 
129  typedef typename WeightImageType::Pointer WeightImagePointer;
130 
131  typedef TWeightPixelType WeightPixelType;
132 
134  void SetInputImage( const InputImageType *in)
135  {
136  this->ProcessObject::SetNthInput(0, const_cast< InputImageType *>(in) );
137  }
138 
140 
143  {
144  this->ProcessObject::SetNthInput(1, const_cast< OutputImageType *>(f) );
145  m_LabelImage = static_cast< OutputImageType *>(this->ProcessObject::GetInput(1));
146  }
147 
149 
152 
155  {
156  this->ProcessObject::SetNthInput(2,const_cast< WeightImageType *>(w));
157  //m_WeightImage = static_cast< WeightImageType *>(this->ProcessObject::GetInput(2));
158  }
159 
161 
163  void SetStateImage( const OutputImageType *l);
165 
166  void SetDistancesImage( const WeightImageType *d);
168 
169  void SetMaxSaturationImage( const WeightImageType *w);
171 
173  itkSetMacro( SeedStrength, double );
174 
176  itkGetConstMacro( SeedStrength, double );
177 
179  itkSetMacro( Labeled, unsigned int);
180  itkGetMacro( Labeled, unsigned int);
181 
183  itkSetMacro( LocallySaturated, unsigned int);
184  itkGetMacro( LocallySaturated, unsigned int);
185 
187  itkSetMacro( Saturated, unsigned int);
188  itkGetMacro( Saturated, unsigned int);
189 
191  itkSetMacro( MaxIterations, unsigned int );
192 
194  itkGetConstMacro( MaxIterations, unsigned int );
195 
197  itkSetMacro( ObjectRadius, unsigned int );
198 
200  itkGetConstMacro( ObjectRadius, unsigned int );
201 
203  void SetROIStart( const OutputIndexType &start)
204  {
205  m_RoiStart = start;
206  }
207 
209  {
210  return m_RoiStart;
211  }
212 
213 
214  void SetROIEnd(const OutputIndexType &end)
215  {
216  m_RoiEnd = end;
217  }
218 
219 
221  {
222  return m_RoiEnd;
223  }
224 
226  itkSetMacro( Radius, InputSizeType );
227 
229  itkGetConstMacro( Radius, InputSizeType );
230 
234  itkSetMacro(RunOneIteration, bool);
235  itkGetConstMacro(RunOneIteration, bool);
236  itkBooleanMacro(RunOneIteration);
237 
238 
246 
251  itkSetMacro(SetStateImage, bool);
254 
262 
263  protected:
264 
267 
268  // Override since the filter needs all the data for the algorithm
269  void GenerateInputRequestedRegion() ITK_OVERRIDE;
270 
271  // Override since the filter produces the entire dataset
272  void EnlargeOutputRequestedRegion(DataObject *output) ITK_OVERRIDE;
273 
274  void GenerateData() ITK_OVERRIDE;
275 
276  void ThreadedGenerateData( const OutputImageRegionType &outputRegionForThread ,
277  ThreadIdType threadId ) ITK_OVERRIDE;
278 
279  void AfterThreadedGenerateData() ITK_OVERRIDE;
280 
281  void Initialize(OutputImageType* output);
282 
283  void PrintSelf ( std::ostream& os, Indent indent ) const ITK_OVERRIDE;
284 
285  void GrowCutSlowROI( TOutputImage *);
286 
287 
288  private:
289 
290  GrowCutSegmentationImageFilter(const Self&); //purposely not implemented
291  void operator=(const Self&); // purposely not implemented
292 
293  bool InitializeStateImage( OutputImageType *state );
294 
295  void InitializeDistancesImage(TInputImage *input,WeightImageType *distance);
296 
297  void GetRegionOfInterest();
298 
299  void ComputeLabelVolumes(TOutputImage *outputImage, std::vector< unsigned > &volumes, std::vector< unsigned > &phyVolumes);
300 
301  void MaskSegmentedImageByWeight(float upperThresh);
302 
303 
304  WeightPixelType m_ConfThresh;
305  InputSizeType m_Radius;
306  OutputImagePointer m_LabelImage;
307  WeightImagePointer m_WeightImage;
308  unsigned int m_Labeled;
309  unsigned int m_LocallySaturated;
310  unsigned int m_Saturated;
311 
312  double m_SeedStrength;
313  bool m_RunOneIteration;
314  bool m_SetStateImage;
315  bool m_SetDistancesImage;
316  bool m_SetMaxSaturationImage;
317 
318  unsigned int m_MaxIterations;
319  unsigned int m_ObjectRadius;
320 
321  OutputPixelType m_ObjectLabel;
322  OutputPixelType m_BackgroundLabel;
323  OutputPixelType m_UnknownLabel;
324 
325  OutputIndexType m_RoiStart;
326  OutputIndexType m_RoiEnd;
327 
328 };
329 
330 } // namespace itk
331 
332 
333 #ifndef ITK_MANUAL_INSTANTIATION
334 #include "itkGrowCutSegmentationImageFilter.txx"
335 #endif
336 
337 #endif
void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, ThreadIdType threadId) ITK_OVERRIDE
void GenerateInputRequestedRegion() ITK_OVERRIDE
const WeightImagePointer GetStrengthImage()
void SetStateImage(const OutputImageType *l)
LRU Cache.
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)