ITK  6.0.0
Insight Toolkit
itkWatershedSegmenter.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
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 * https://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
24#include "itkEquivalencyTable.h"
25
26namespace itk
27{
28namespace watershed
29{
88template <typename TInputImage>
89class ITK_TEMPLATE_EXPORT Segmenter : public ProcessObject
90{
91public:
92
94 using Self = Segmenter;
95
97 using InputImageType = TInputImage;
98 static constexpr unsigned int ImageDimension = TInputImage::ImageDimension;
99
102 using InputPixelType = typename InputImageType::PixelType;
108
114 itkNewMacro(Self);
115 itkOverrideGetNameOfClassMacro(Segmenter);
123
125 static constexpr IdentifierType NULL_LABEL = 0;
126
128 static constexpr short NULL_FLOW = -1;
129
133 {
134 return itkDynamicCastInDebugMode<InputImageType *>(this->ProcessObject::GetInput(0));
135 }
136
137 void
139 {
140 this->ProcessObject::SetNthInput(0, img);
141 }
142
145 OutputImageType *
147 {
148 return itkDynamicCastInDebugMode<OutputImageType *>(this->ProcessObject::GetOutput(0));
149 }
150
151 void
153 {
154 this->ProcessObject::SetNthOutput(0, img);
155 }
156
159 SegmentTableType *
161 {
162 return itkDynamicCastInDebugMode<SegmentTableType *>(this->ProcessObject::GetOutput(1));
163 }
164
165 void
167 {
168 this->ProcessObject::SetNthOutput(1, s);
169 }
170
173 BoundaryType *
175 {
176 return itkDynamicCastInDebugMode<BoundaryType *>(this->ProcessObject::GetOutput(2));
177 }
178
179 void
181 {
182 this->ProcessObject::SetNthOutput(2, b);
183 }
184
186 void
187 GenerateData() override;
188
195 void
197 {
198 if (reg == m_LargestPossibleRegion)
199 {
200 return;
201 }
202 m_LargestPossibleRegion = reg;
203 this->Modified();
204 }
207 ImageRegionType
209 {
210 return m_LargestPossibleRegion;
211 }
212
216
219 using Superclass::MakeOutput;
222
225 itkSetMacro(CurrentLabel, IdentifierType);
226 itkGetConstMacro(CurrentLabel, IdentifierType);
239 itkSetClampMacro(Threshold, double, 0.0, 1.0);
240 itkGetConstMacro(Threshold, double);
246 itkSetMacro(DoBoundaryAnalysis, bool);
247 itkGetConstMacro(DoBoundaryAnalysis, bool);
254 itkGetConstMacro(SortEdgeLists, bool);
255 itkSetMacro(SortEdgeLists, bool);
258protected:
262 {
265 // InputPixelType bounds_max; // <-- may not be necc.
267 bool is_on_boundary{ false };
268 flat_region_t() = default;
269 };
270
272 using flat_region_table_t = std::unordered_map<IdentifierType, flat_region_t>;
273
275 {
276 unsigned int size;
277 unsigned int * index;
278 typename InputImageType::OffsetType * direction;
279 };
280
285 using edge_table_t = std::map<IdentifierType, InputPixelType>;
286
287 using edge_table_hash_t = std::unordered_map<IdentifierType, edge_table_t>;
288
290 Segmenter(const Self &) {}
291 ~Segmenter() override;
292 void
293 PrintSelf(std::ostream & os, Indent indent) const override;
294
295 void
297 {}
298
301 virtual void
303
307 void
309
310 void
312
313 void
315
318 void
320
324 void
326
331
334 void
336
341
344 void
346
350
354 void
356
362 static void
365 const ImageRegionType source_region,
366 const ImageRegionType destination_region,
367 InputPixelType threshold);
368
370 static void
372
374 static void
376
378 static void
380
381 static void
383
385 // bool CheckLabeledBoundaries();
386
389 connectivity_t m_Connectivity{};
390
391private:
393 // void PrintFlatRegions(flat_region_table_t &t);
394
398 ImageRegionType m_LargestPossibleRegion{};
399
400 bool m_SortEdgeLists{};
401 bool m_DoBoundaryAnalysis{};
402 double m_Threshold{};
403 double m_MaximumFloodLevel{};
404 IdentifierType m_CurrentLabel{};
405};
406} // end namespace watershed
407} // end namespace itk
408
409#ifndef ITK_MANUAL_INSTANTIATION
410# include "itkWatershedSegmenter.hxx"
411#endif
412
413#endif
Base class for all data objects in ITK.
SmartPointer< Self > Pointer
Templated n-dimensional image class.
Definition: itkImage.h:89
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
DataObject * GetOutput(const DataObjectIdentifierType &key)
DataObjectPointerArray::size_type DataObjectPointerArraySizeType
virtual void SetNthInput(DataObjectPointerArraySizeType idx, DataObject *input)
DataObject * GetInput(const DataObjectIdentifierType &key)
Return an input.
virtual void SetNthOutput(DataObjectPointerArraySizeType idx, DataObject *output)
typename flat_hash_t::value_type FlatHashValueType
static void MinMax(InputImageTypePointer img, ImageRegionType region, InputPixelType &min, InputPixelType &max)
void DescendFlatRegions(flat_region_table_t &, ImageRegionType)
void PrintSelf(std::ostream &os, Indent indent) const override
typename OutputImageType::Pointer OutputImageTypePointer
SegmentTableType * GetSegmentTable()
void GradientDescent(InputImageTypePointer, ImageRegionType)
std::unordered_map< IdentifierType, edge_table_t > edge_table_hash_t
typename BoundaryType::Pointer BoundaryTypePointer
void SetBoundary(BoundaryType *b)
ImageRegionType GetLargestPossibleRegion() const
static void SetInputImageValues(InputImageTypePointer img, const ImageRegionType region, InputPixelType value)
void SetInputImage(InputImageType *img)
void SetLargestPossibleRegion(ImageRegionType reg)
void LabelMinima(InputImageTypePointer, ImageRegionType, flat_region_table_t &, InputPixelType)
std::map< IdentifierType, InputPixelType > edge_table_t
typename InputImageType::RegionType ImageRegionType
static void Threshold(InputImageTypePointer destination, InputImageTypePointer source, const ImageRegionType source_region, const ImageRegionType destination_region, InputPixelType threshold)
typename InputImageType::PixelType InputPixelType
void UpdateOutputInformation() override
Update the information describing the output data.
OutputImageType * GetOutputImage()
typename BoundaryType::IndexType BoundaryIndexType
static void SetOutputImageValues(OutputImageTypePointer img, const ImageRegionType region, IdentifierType value)
void UpdateSegmentTable(InputImageTypePointer, ImageRegionType)
std::unordered_map< IdentifierType, flat_region_t > flat_region_table_t
typename InputImageType::Pointer InputImageTypePointer
void BuildRetainingWall(InputImageTypePointer, ImageRegionType, InputPixelType)
DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx) override
Make a DataObject of the correct type to used as the specified output.
virtual void GenerateConnectivity()
static void RelabelImage(OutputImageTypePointer, ImageRegionType, EquivalencyTable::Pointer)
void GenerateOutputRequestedRegion(DataObject *output) override
typename BoundaryType::FlatHashValueType BoundaryFlatHashValueType
void CollectBoundaryInformation(flat_region_table_t &)
void AnalyzeBoundaryFlow(InputImageTypePointer, flat_region_table_t &, InputPixelType)
void SetSegmentTable(SegmentTableType *s)
void GenerateInputRequestedRegion() override
static void MergeFlatRegions(flat_region_table_t &, EquivalencyTable::Pointer)
void SetOutputImage(OutputImageType *img)
typename SegmentTableType::Pointer SegmentTableTypePointer
void GenerateData() override
SmartPointer< Self > Pointer
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
class ITK_FORWARD_EXPORT ProcessObject
Definition: itkDataObject.h:41
SizeValueType IdentifierType
Definition: itkIntTypes.h:90