ITK  5.2.0
Insight Toolkit
itkWatershedImageFilter.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  * 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 itkWatershedImageFilter_h
19 #define itkWatershedImageFilter_h
20 
21 
22 #include "itkImageToImageFilter.h"
24 #include "itkWatershedRelabeler.h"
26 
27 namespace itk
28 {
148 template <typename TInputImage>
149 class ITK_TEMPLATE_EXPORT WatershedImageFilter
150  : public ImageToImageFilter<TInputImage, Image<IdentifierType, TInputImage::ImageDimension>>
151 {
152 public:
153  ITK_DISALLOW_COPY_AND_MOVE(WatershedImageFilter);
154 
157 
159  using InputImageType = TInputImage;
160 
162  static constexpr unsigned int ImageDimension = TInputImage::ImageDimension;
163 
166 
171 
174 
176  using ScalarType = typename InputImageType::PixelType;
177 
180 
183 
185  itkNewMacro(Self);
186 
188  void
189  GenerateData() override;
190 
193  using Superclass::SetInput;
194  void
195  SetInput(const InputImageType * input) override
196  {
197  // if the input is changed, we'll need to clear the cached tree
198  // when we execute
199  if (input != this->GetInput(0))
200  {
201  m_InputChanged = true;
202  }
204 
205  // processObject is not const-correct so a const_cast is needed here
206  this->ProcessObject::SetNthInput(0, const_cast<InputImageType *>(input));
207  m_Segmenter->SetInputImage(const_cast<InputImageType *>(input));
208  }
209 
210  void
211  SetInput(unsigned int i, const TInputImage * image) override
212  {
213  if (i != 0)
214  {
215  itkExceptionMacro(<< "Filter has only one input.");
216  }
217  else
218  {
219  this->SetInput(image);
220  }
221  }
222 
225  void
226  SetThreshold(double);
227 
228  itkGetConstMacro(Threshold, double);
229 
232  void
233  SetLevel(double);
234 
235  itkGetConstMacro(Level, double);
236 
240  {
241  m_Segmenter->Update();
242  return m_Segmenter->GetOutputImage();
243  }
245 
249  {
250  return m_TreeGenerator->GetOutputSegmentTree();
251  }
252 
253  // Override since the filter produces all of its output
254  void
255  EnlargeOutputRequestedRegion(DataObject * data) override;
256 
257 #ifdef ITK_USE_CONCEPT_CHECKING
258  // Begin concept checking
259  itkConceptMacro(InputEqualityComparableCheck, (Concept::EqualityComparable<ScalarType>));
260  itkConceptMacro(InputAdditiveOperatorsCheck, (Concept::AdditiveOperators<ScalarType>));
262  itkConceptMacro(InputLessThanComparableCheck, (Concept::LessThanComparable<ScalarType>));
263  // End concept checking
264 #endif
265 
266 protected:
268  ~WatershedImageFilter() override = default;
269  void
270  PrintSelf(std::ostream & os, Indent indent) const override;
271 
274  void
275  PrepareOutputs() override;
276 
277 private:
281  double m_Threshold{ 0.0 };
282 
287  double m_Level{ 0.0 };
288 
294 
296 
298 
299  unsigned long m_ObserverTag;
300 
304 
306 };
307 } // end namespace itk
308 
309 #ifndef ITK_MANUAL_INSTANTIATION
310 # include "itkWatershedImageFilter.hxx"
311 #endif
312 
313 #endif
itk::WatershedImageFilter::m_ObserverTag
unsigned long m_ObserverTag
Definition: itkWatershedImageFilter.h:299
itkWatershedSegmentTreeGenerator.h
itk::WatershedImageFilter::m_GenerateDataMTime
TimeStamp m_GenerateDataMTime
Definition: itkWatershedImageFilter.h:305
itkWatershedMiniPipelineProgressCommand.h
itk::WatershedImageFilter::ScalarType
typename InputImageType::PixelType ScalarType
Definition: itkWatershedImageFilter.h:176
itk::WatershedImageFilter::SetInput
void SetInput(unsigned int i, const TInputImage *image) override
Definition: itkWatershedImageFilter.h:211
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itk::WatershedImageFilter::SizeType
typename InputImageType::SizeType SizeType
Definition: itkWatershedImageFilter.h:169
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::WatershedImageFilter::GetBasicSegmentation
watershed::Segmenter< InputImageType >::OutputImageType * GetBasicSegmentation()
Definition: itkWatershedImageFilter.h:239
itk::WatershedImageFilter
A low-level image analysis algorithm that automatically produces a hierarchy of segmented,...
Definition: itkWatershedImageFilter.h:149
itkWatershedRelabeler.h
itk::ProcessObject::Update
virtual void Update()
Bring this filter up-to-date.
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::ImageToImageFilter
Base class for filters that take an image as input and produce an image as output.
Definition: itkImageToImageFilter.h:108
itk::WatershedImageFilter::SetInput
void SetInput(const InputImageType *input) override
Definition: itkWatershedImageFilter.h:195
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::WatershedImageFilter::m_Relabeler
watershed::Relabeler< ScalarType, Self::ImageDimension >::Pointer m_Relabeler
Definition: itkWatershedImageFilter.h:297
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::WatershedImageFilter::RegionType
typename InputImageType::RegionType RegionType
Definition: itkWatershedImageFilter.h:168
itk::WatershedImageFilter::IndexType
typename InputImageType::IndexType IndexType
Definition: itkWatershedImageFilter.h:170
itk::TimeStamp
Generate a unique, increasing time value.
Definition: itkTimeStamp.h:60
itkImageToImageFilter.h
itk::Concept::MultiplyOperator
Definition: itkConceptChecking.h:419
itk::WatershedImageFilter::m_TreeGenerator
watershed::SegmentTreeGenerator< ScalarType >::Pointer m_TreeGenerator
Definition: itkWatershedImageFilter.h:295
itk::Concept::AdditiveOperators
Definition: itkConceptChecking.h:358
itk::WatershedImageFilter::m_LevelChanged
bool m_LevelChanged
Definition: itkWatershedImageFilter.h:301
itkConceptMacro
#define itkConceptMacro(name, concept)
Definition: itkConceptChecking.h:65
itk::watershed::SegmentTree
Definition: itkWatershedSegmentTree.h:48
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ProcessObject::SetNthInput
virtual void SetNthInput(DataObjectPointerArraySizeType idx, DataObject *input)
itk::WatershedImageFilter::m_Segmenter
watershed::Segmenter< InputImageType >::Pointer m_Segmenter
Definition: itkWatershedImageFilter.h:293
itk::watershed::SegmentTreeGenerator::GetOutputSegmentTree
SegmentTreeType * GetOutputSegmentTree()
Definition: itkWatershedSegmentTreeGenerator.h:142
itk::WatershedImageFilter::m_InputChanged
bool m_InputChanged
Definition: itkWatershedImageFilter.h:303
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:86
itk::WatershedImageFilter::InputImageType
TInputImage InputImageType
Definition: itkWatershedImageFilter.h:159
itk::WatershedImageFilter::m_ThresholdChanged
bool m_ThresholdChanged
Definition: itkWatershedImageFilter.h:302
itk::Concept::EqualityComparable
Definition: itkConceptChecking.h:306
itk::Concept::LessThanComparable
Definition: itkConceptChecking.h:262
itk::DataObject
Base class for all data objects in ITK.
Definition: itkDataObject.h:293
itk::WatershedImageFilter::GetSegmentTree
watershed::SegmentTreeGenerator< ScalarType >::SegmentTreeType * GetSegmentTree()
Definition: itkWatershedImageFilter.h:248