Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
itkIntelligentBinaryClosingFilter.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 #ifndef itkIntelligentBinaryClosingFilter_h
13 #define itkIntelligentBinaryClosingFilter_h
14 
15 #include <itkBinaryBallStructuringElement.h>
16 #include <itkBinaryDilateImageFilter.h>
17 #include <itkBinaryErodeImageFilter.h>
18 #include <itkConnectedComponentImageFilter.h>
19 #include <itkConnectedComponentImageFilter.h>
20 #include <itkGrayscaleDilateImageFilter.h>
21 #include <itkImageRegionIterator.h>
22 #include <itkImageToImageFilter.h>
23 #include <itkRelabelComponentImageFilter.h>
24 #include <itkSubtractImageFilter.h>
25 
26 namespace itk
27 {
48  template <class TInputImage, class TOutputImage>
49  class ITK_EXPORT IntelligentBinaryClosingFilter : public ImageToImageFilter<TInputImage, TOutputImage>
50  {
51  public:
54 
56  typedef TInputImage InputImageType;
57 
59  itkStaticConstMacro(ImageDimension, unsigned int, TInputImage::ImageDimension);
60 
62  typedef TOutputImage OutputImageType;
63 
65  typedef ImageToImageFilter<InputImageType, OutputImageType> Superclass;
66 
69 
71  itkTypeMacro(IntelligentBinaryClosingFilter, ImageToImageFilter);
72 
74  itkFactorylessNewMacro(Self);
75  itkCloneMacro(Self);
76 
84  void GenerateData() override;
85 
93  void SetInput(const InputImageType *input) override
94  {
95  // processObject is not const-correct so a const_cast is needed here
96  this->ProcessObject::SetNthInput(0, const_cast<InputImageType *>(input));
97  m_DilateImageFilter->SetInput(input);
98  }
99 
100  using Superclass::SetInput;
107  void SetInput(unsigned int i, const TInputImage *image) override
108  {
109  if (i != 0)
110  {
111  itkExceptionMacro(<< "Filter has only one input.");
112  }
113  else
114  {
115  this->SetInput(image);
116  }
117  }
118 
123  itkGetMacro(ClosingRadius, float);
124 
129  itkSetMacro(ClosingRadius, float);
130 
135  itkGetMacro(SurfaceRatio, float);
136 
145  itkSetMacro(SurfaceRatio, float);
146 
147  protected:
150  void PrintSelf(std::ostream &os, Indent indent) const override;
151 
152  private:
153  typedef typename InputImageType::PixelType InputPixelType;
154  typedef BinaryBallStructuringElement<InputPixelType, ImageDimension> StructuringElementType;
155  typedef BinaryErodeImageFilter<InputImageType, InputImageType, StructuringElementType> BinaryErodeImageFilterType;
156  typedef BinaryDilateImageFilter<InputImageType, InputImageType, StructuringElementType> BinaryDilateImageFilterType;
157  typedef SubtractImageFilter<InputImageType, InputImageType, InputImageType> SubtractImageFilterType;
158  typedef ConnectedComponentImageFilter<InputImageType, OutputImageType> ConnectedComponentImageFilterType;
159  typedef RelabelComponentImageFilter<OutputImageType, OutputImageType> RelabelComponentImageFilterType;
160  typedef GrayscaleDilateImageFilter<OutputImageType, OutputImageType, StructuringElementType>
161  DilateComponentImageFilterType;
162  typedef ImageRegionIterator<InputImageType> InputIteratorType;
163  typedef ImageRegionConstIterator<InputImageType> ConstInputIteratorType;
164  typedef ImageRegionIterator<OutputImageType> OutputIteratorType;
165 
166  typename BinaryErodeImageFilterType::Pointer m_ErodeImageFilter;
167  typename BinaryDilateImageFilterType::Pointer m_DilateImageFilter;
168  typename SubtractImageFilterType::Pointer m_SubtractImageFilter;
169  typename ConnectedComponentImageFilterType::Pointer m_ConnectedComponentImageFilter;
170  typename RelabelComponentImageFilterType::Pointer m_RelabelComponentImageFilter;
171  typename DilateComponentImageFilterType::Pointer m_BorderDetectionDilateFilter;
172  // typename BinaryDilateImageFilterType::Pointer m_BorderAdjacencyDilateFilter;
173  float m_ClosingRadius;
174  float m_SurfaceRatio;
175  };
176 
177 } // end namespace itk
178 
179 #ifndef ITK_MANUAL_INSTANTIATION
180 #include <itkIntelligentBinaryClosingFilter.tpp>
181 
182 #endif
183 
184 #endif // IntelligentBinaryClosingFilter_h
Performs a morphological closing on a binary image, selectively filling only those holes whose surfac...
void PrintSelf(std::ostream &os, Indent indent) const override
itkStaticConstMacro(ImageDimension, unsigned int, TInputImage::ImageDimension)
void GenerateData() override
Execute the intelligent binary closing algorithm.
ImageToImageFilter< InputImageType, OutputImageType > Superclass
void SetInput(unsigned int i, const TInputImage *image) override
Set the input at a given index. Only index 0 is supported.
void SetInput(const InputImageType *input) override
Set the input binary image.