ITK  4.8.0
Insight Segmentation and Registration Toolkit
itkWatershedSegmenter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkWatershedSegmenter_h
19 #define itkWatershedSegmenter_h
20 
21 
22 #include "itkWatershedBoundary.h"
24 #include "itkEquivalencyTable.h"
25 
26 namespace itk
27 {
28 namespace watershed
29 {
87 template< typename TInputImage >
88 class Segmenter:
89  public ProcessObject
90 {
91 public:
93  typedef Segmenter Self;
94 
96  typedef TInputImage InputImageType;
97  itkStaticConstMacro(ImageDimension, unsigned int,
98  TInputImage::ImageDimension);
99 
102  typedef typename InputImageType::RegionType ImageRegionType;
103  typedef typename InputImageType::PixelType InputPixelType;
110 
116  itkNewMacro(Self);
117  itkTypeMacro(WatershedSegmenter, ProcessObject);
119 
121  typedef typename InputImageType::Pointer InputImageTypePointer;
125 
127  itkStaticConstMacro(NULL_LABEL, unsigned long, 0);
128 
130  itkStaticConstMacro(NULL_FLOW, unsigned long, -1);
131 
134  {
135  return itkDynamicCastInDebugMode< InputImageType * >
136  ( this->ProcessObject::GetInput(0) );
137  }
138 
140  { this->ProcessObject::SetNthInput(0, img); }
141 
145  {
146  return itkDynamicCastInDebugMode< OutputImageType * >
147  ( this->ProcessObject::GetOutput(0) );
148  }
149 
151  { this->ProcessObject::SetNthOutput(0, img); }
152 
156  {
157  return itkDynamicCastInDebugMode< SegmentTableType * >
158  ( this->ProcessObject::GetOutput(1) );
159  }
160 
162  { this->ProcessObject::SetNthOutput(1, s); }
163 
167  {
168  return itkDynamicCastInDebugMode< BoundaryType * >
169  ( this->ProcessObject::GetOutput(2) );
170  }
171 
173  { this->ProcessObject::SetNthOutput(2, b); }
174 
176  virtual void GenerateData() ITK_OVERRIDE;
177 
185  {
186  if ( reg == m_LargestPossibleRegion ) { return; }
188  this->Modified();
189  }
191 
193  { return m_LargestPossibleRegion; }
194 
200 
205 
208  itkSetMacro(CurrentLabel, IdentifierType);
209  itkGetConstMacro(CurrentLabel, IdentifierType);
211 
222  itkSetClampMacro(Threshold, double, 0.0, 1.0);
223  itkGetConstMacro(Threshold, double);
225 
229  itkSetMacro(DoBoundaryAnalysis, bool);
230  itkGetConstMacro(DoBoundaryAnalysis, bool);
232 
237  itkGetConstMacro(SortEdgeLists, bool);
238  itkSetMacro(SortEdgeLists, bool);
240 
241 protected:
244  struct flat_region_t {
247  // InputPixelType bounds_max; // <-- may not be necc.
251  };
252 
254  typedef itksys::hash_map< IdentifierType, flat_region_t, itksys::hash< IdentifierType > >
256 
257  struct connectivity_t {
258  unsigned int size;
259  unsigned int *index;
260  typename InputImageType::OffsetType * direction;
261  };
262 
267  typedef itksys::hash_map< IdentifierType, InputPixelType, itksys::hash< IdentifierType >
269 
270  typedef itksys::hash_map< IdentifierType, edge_table_t, itksys::hash< IdentifierType >
272 
273  Segmenter();
274  Segmenter(const Self &) {}
275  virtual ~Segmenter();
276  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
277 
278  void operator=(const Self &) {}
279 
282  virtual void GenerateConnectivity();
283 
287  virtual void GenerateInputRequestedRegion() ITK_OVERRIDE;
288 
289  virtual void GenerateOutputRequestedRegion(DataObject *output) ITK_OVERRIDE;
290 
291  virtual void UpdateOutputInformation() ITK_OVERRIDE;
292 
295  void InitializeBoundary();
296 
303 
307  void BuildRetainingWall(InputImageTypePointer,
308  ImageRegionType, InputPixelType);
309 
312  void LabelMinima(InputImageTypePointer,
313  ImageRegionType, flat_region_table_t &,
314  InputPixelType);
315 
319  void GradientDescent(InputImageTypePointer, ImageRegionType);
320 
323  void DescendFlatRegions(flat_region_table_t &, ImageRegionType);
324 
327  void UpdateSegmentTable(InputImageTypePointer, ImageRegionType);
328 
332  void CollectBoundaryInformation(flat_region_table_t &);
333 
339  static void Threshold(InputImageTypePointer destination,
340  InputImageTypePointer source,
341  const ImageRegionType source_region,
342  const ImageRegionType destination_region,
343  InputPixelType threshold);
344 
346  static void MinMax(InputImageTypePointer img,
347  ImageRegionType region,
348  InputPixelType & min,
349  InputPixelType & max);
350 
352  static void MergeFlatRegions(flat_region_table_t &, EquivalencyTable::Pointer);
353 
355  static void SetInputImageValues(InputImageTypePointer img,
356  const ImageRegionType region,
357  InputPixelType value);
358 
360  const ImageRegionType region,
361  IdentifierType value);
362 
364  // bool CheckLabeledBoundaries();
365 
368  connectivity_t m_Connectivity;
369 
370 private:
372  // void PrintFlatRegions(flat_region_table_t &t);
373 
377  ImageRegionType m_LargestPossibleRegion;
378 
381  double m_Threshold;
384 };
385 } // end namespace watershed
386 } // end namespace itk
387 
388 #ifndef ITK_MANUAL_INSTANTIATION
389 #include "itkWatershedSegmenter.hxx"
390 #endif
391 
392 #endif
flat_hash_t::value_type FlatHashValueType
OutputImageType * GetOutputImage(void)
virtual void GenerateConnectivity()
itksys::hash_map< IdentifierType, edge_table_t, itksys::hash< IdentifierType > > edge_table_hash_t
Light weight base class for most itk classes.
BoundaryType::FlatHashValueType BoundaryFlatHashValueType
virtual void GenerateInputRequestedRegion() override
static void SetOutputImageValues(OutputImageTypePointer img, const ImageRegionType region, IdentifierType value)
SegmentTableType::Pointer SegmentTableTypePointer
virtual void GenerateData() override
ImageRegionType GetLargestPossibleRegion() const
SmartPointer< const Self > ConstPointer
SegmentTable< InputPixelType > SegmentTableType
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType
static const unsigned int ImageDimension
void SetOutputImage(OutputImageType *img)
std::pair< unsigned, unsigned > IndexType
InputImageType::Pointer InputImageTypePointer
void BuildRetainingWall(InputImageTypePointer, ImageRegionType, InputPixelType)
void DescendFlatRegions(flat_region_table_t &, ImageRegionType)
InputImageType * GetInputImage(void)
InputImageType::PixelType InputPixelType
SegmentTableType * GetSegmentTable(void)
Boundary< InputPixelType, itkGetStaticConstMacro(ImageDimension) > BoundaryType
void AnalyzeBoundaryFlow(InputImageTypePointer, flat_region_table_t &, InputPixelType)
SizeValueType IdentifierType
Definition: itkIntTypes.h:147
DataObject::Pointer DataObjectPointer
Hash table to manage integral label equivalencies.
InputImageType::RegionType ImageRegionType
void SetLargestPossibleRegion(ImageRegionType reg)
DataObjectPointerArray::size_type DataObjectPointerArraySizeType
static const unsigned long NULL_LABEL
virtual void GenerateOutputRequestedRegion(DataObject *output) override
virtual DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx) override
Make a DataObject of the correct type to used as the specified output.
static const unsigned long NULL_FLOW
static void RelabelImage(OutputImageTypePointer, ImageRegionType, EquivalencyTable::Pointer)
itksys::hash_map< IdentifierType, InputPixelType, itksys::hash< IdentifierType > > edge_table_t
virtual DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx)
Make a DataObject of the correct type to used as the specified output.
void LabelMinima(InputImageTypePointer, ImageRegionType, flat_region_table_t &, InputPixelType)
virtual void Modified() const
BoundaryType::Pointer BoundaryTypePointer
DataObject * GetInput(const DataObjectIdentifierType &key)
Return an input.
Image< IdentifierType, itkGetStaticConstMacro(ImageDimension) > OutputImageType
virtual void UpdateOutputInformation() override
Update the information describing the output data.
void UpdateSegmentTable(InputImageTypePointer, ImageRegionType)
BoundaryType * GetBoundary(void)
virtual void PrintSelf(std::ostream &os, Indent indent) const override
void SetSegmentTable(SegmentTableType *s)
OutputImageType::Pointer OutputImageTypePointer
static void MergeFlatRegions(flat_region_table_t &, EquivalencyTable::Pointer)
Control indentation during Print() invocation.
Definition: itkIndent.h:49
static void Threshold(InputImageTypePointer destination, InputImageTypePointer source, const ImageRegionType source_region, const ImageRegionType destination_region, InputPixelType threshold)
itksys::hash_map< IdentifierType, flat_region_t, itksys::hash< IdentifierType > > flat_region_table_t
virtual void SetNthInput(DataObjectPointerArraySizeType num, DataObject *input)
BoundaryType::IndexType BoundaryIndexType
virtual void SetNthOutput(DataObjectPointerArraySizeType num, DataObject *output)
static void MinMax(InputImageTypePointer img, ImageRegionType region, InputPixelType &min, InputPixelType &max)
void SetBoundary(BoundaryType *b)
Base class for all data objects in ITK.
Templated n-dimensional image class.
Definition: itkImage.h:75
void SetInputImage(InputImageType *img)
void CollectBoundaryInformation(flat_region_table_t &)
void GradientDescent(InputImageTypePointer, ImageRegionType)
DataObject * GetOutput(const DataObjectIdentifierType &key)
static void SetInputImageValues(InputImageTypePointer img, const ImageRegionType region, InputPixelType value)