ITK  5.4.0
Insight Toolkit
itkKernelImageFilter.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 itkKernelImageFilter_h
19 #define itkKernelImageFilter_h
20 
21 #include "itkBoxImageFilter.h"
22 
23 namespace itk
24 {
25 
26 template <unsigned int VDimension>
39 template< typename TInputImage, typename TOutputImage, typename TKernel /*=Neighborhood<bool,
40  TInputImage::ImageDimension>*/ >
41 class ITK_TEMPLATE_EXPORT KernelImageFilter:
42  public BoxImageFilter< TInputImage, TOutputImage >
43 {
44 public:
45  ITK_DISALLOW_COPY_AND_MOVE(KernelImageFilter);
46 
52 
54  itkNewMacro(Self);
55 
57  itkOverrideGetNameOfClassMacro(KernelImageFilter);
58 
60  using InputImageType = TInputImage;
62  using SizeType = typename TInputImage::SizeType;
64  using OffsetType = typename TInputImage::OffsetType;
65 
66  using InputPixelType = typename TInputImage::PixelType;
67 
68  using OutputImageType = TOutputImage;
69  using OutputPixelType = typename TOutputImage::PixelType;
70 
71  using KernelType = TKernel;
72 
74  static constexpr unsigned int ImageDimension = TInputImage::ImageDimension;
75 
77  using FlatKernelType = FlatStructuringElement<(Self::ImageDimension)>;
78 
81 
83  virtual void
84  SetKernel(const KernelType & kernel);
85 
86  itkGetConstReferenceMacro(Kernel, KernelType);
87 
89  void
90  SetRadius(const RadiusType & radius) override;
91 
92  void
93  SetRadius(const SizeValueType & radius) override
94  {
95  // needed because of the overloading of the method
96  Superclass::SetRadius(radius);
97  }
98 
99 protected:
101  ~KernelImageFilter() override = default;
102 
103  void
104  PrintSelf(std::ostream & os, Indent indent) const override;
105 
107  KernelType m_Kernel{};
108 
109 private:
110  template <typename T>
111  void
112  MakeKernel(const RadiusType & radius, T & kernel)
113  {
114  kernel.SetRadius(radius);
115  for (typename T::Iterator kit = kernel.Begin(); kit != kernel.End(); ++kit)
116  {
117  *kit = 1;
118  }
119  }
120 
121  void
122  MakeKernel(const RadiusType & radius, FlatKernelType & kernel)
123  {
124  // set up a decomposable box structuring element which is
125  // much efficient with van Herk / Gil Werman filters
126  kernel = FlatKernelType::Box(radius);
127  assert(kernel.GetDecomposable());
128  }
129 };
130 } // namespace itk
131 
132 #ifndef ITK_MANUAL_INSTANTIATION
133 # include "itkKernelImageFilter.hxx"
134 #endif
135 
136 #endif
itk::KernelImageFilter::SetRadius
void SetRadius(const SizeValueType &radius) override
Definition: itkKernelImageFilter.h:93
itk::BoxImageFilter::OutputPixelType
typename TOutputImage::PixelType OutputPixelType
Definition: itkBoxImageFilter.h:67
itk::FlatStructuringElement
A class to support a variety of flat structuring elements, including versions created by decompositio...
Definition: itkKernelImageFilter.h:27
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::BoxImageFilter
A base class for all the filters working on a box neighborhood.
Definition: itkBoxImageFilter.h:40
itk::BoxImageFilter::RadiusType
typename TInputImage::SizeType RadiusType
Definition: itkBoxImageFilter.h:73
itk::BoxImageFilter::OffsetType
typename TInputImage::OffsetType OffsetType
Definition: itkBoxImageFilter.h:62
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::ImageSource
Base class for all process objects that output image data.
Definition: itkImageSource.h:67
itk::BoxImageFilter::InputPixelType
typename TInputImage::PixelType InputPixelType
Definition: itkBoxImageFilter.h:64
itk::BoxImageFilter::IndexType
typename TInputImage::IndexType IndexType
Definition: itkBoxImageFilter.h:61
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::KernelImageFilter::MakeKernel
void MakeKernel(const RadiusType &radius, T &kernel)
Definition: itkKernelImageFilter.h:112
itk::ImageToImageFilter::InputImageType
TInputImage InputImageType
Definition: itkImageToImageFilter.h:129
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::KernelImageFilter::MakeKernel
void MakeKernel(const RadiusType &radius, FlatKernelType &kernel)
Definition: itkKernelImageFilter.h:122
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:139
itk::KernelImageFilter< TImage, TImage, TKernel >::KernelType
TKernel KernelType
Definition: itkKernelImageFilter.h:71
itkBoxImageFilter.h
itk::BoxImageFilter::SizeType
typename TInputImage::SizeType SizeType
Definition: itkBoxImageFilter.h:60
itk::KernelImageFilter
A base class for all the filters working on an arbitrary shaped neighborhood.
Definition: itkKernelImageFilter.h:41
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83
itk::ImageSource::OutputImageType
TOutputImage OutputImageType
Definition: itkImageSource.h:90
itk::FlatStructuringElement::GetDecomposable
bool GetDecomposable() const
Definition: itkFlatStructuringElement.h:168
itk::BoxImageFilter::RegionType
typename TInputImage::RegionType RegionType
Definition: itkBoxImageFilter.h:59