ITK  4.13.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 ITK_TEMPLATE_EXPORT 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, IdentifierType, 0);
128 
130  itkStaticConstMacro(NULL_FLOW, short, -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 
184  void SetLargestPossibleRegion(ImageRegionType reg)
185  {
186  if ( reg == m_LargestPossibleRegion ) { return; }
187  m_LargestPossibleRegion = reg;
188  this->Modified();
189  }
191 
193  { return m_LargestPossibleRegion; }
194 
197  static void RelabelImage(OutputImageTypePointer,
198  ImageRegionType,
200 
203  using Superclass::MakeOutput;
204  virtual DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx) ITK_OVERRIDE;
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.
250  flat_region_t():is_on_boundary(false) {}
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() ITK_OVERRIDE;
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 
300  void AnalyzeBoundaryFlow(InputImageTypePointer,
301  flat_region_table_t &,
302  InputPixelType);
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 
359  static void SetOutputImageValues(OutputImageTypePointer img,
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 
379  bool m_SortEdgeLists;
380  bool m_DoBoundaryAnalysis;
381  double m_Threshold;
382  double m_MaximumFloodLevel;
383  IdentifierType m_CurrentLabel;
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)
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
SegmentTableType::Pointer SegmentTableTypePointer
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
void SetOutputImage(OutputImageType *img)
std::pair< unsigned, unsigned > IndexType
InputImageType::Pointer InputImageTypePointer
InputImageType * GetInputImage(void)
InputImageType::PixelType InputPixelType
SegmentTableType * GetSegmentTable(void)
Boundary< InputPixelType, itkGetStaticConstMacro(ImageDimension) > BoundaryType
SizeValueType IdentifierType
Definition: itkIntTypes.h:147
DataObject::Pointer DataObjectPointer
Hash table to manage integral label equivalencies.
InputImageType::RegionType ImageRegionType
DataObjectPointerArray::size_type DataObjectPointerArraySizeType
itksys::hash_map< IdentifierType, InputPixelType, itksys::hash< IdentifierType > > edge_table_t
BoundaryType::Pointer BoundaryTypePointer
DataObject * GetInput(const DataObjectIdentifierType &key)
Return an input.
Image< IdentifierType, itkGetStaticConstMacro(ImageDimension) > OutputImageType
BoundaryType * GetBoundary(void)
void SetSegmentTable(SegmentTableType *s)
OutputImageType::Pointer OutputImageTypePointer
Control indentation during Print() invocation.
Definition: itkIndent.h:49
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)
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)
DataObject * GetOutput(const DataObjectIdentifierType &key)