ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkKernelImageFilter.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 itkKernelImageFilter_h
19 #define itkKernelImageFilter_h
20 
21 #include "itkBoxImageFilter.h"
22 
23 namespace itk
24 {
25 
26 template< unsigned int VDimension > class FlatStructuringElement;
38 template< typename TInputImage, typename TOutputImage, typename TKernel /*=Neighborhood<bool,
39  TInputImage::ImageDimension>*/ >
40 class ITK_TEMPLATE_EXPORT KernelImageFilter:
41  public BoxImageFilter< TInputImage, TOutputImage >
42 {
43 public:
44  ITK_DISALLOW_COPY_AND_ASSIGN(KernelImageFilter);
45 
51 
53  itkNewMacro(Self);
54 
56  itkTypeMacro(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 
78 
81 
83  virtual void SetKernel(const KernelType & kernel);
84 
85  itkGetConstReferenceMacro(Kernel, KernelType);
86 
88  void SetRadius(const RadiusType & radius) override;
89 
90  void SetRadius(const SizeValueType & radius) override
91  {
92  // needed because of the overloading of the method
93  Superclass::SetRadius(radius);
94  }
95 
96 protected:
98  ~KernelImageFilter() override = default;
99 
100  void PrintSelf(std::ostream & os, Indent indent) const override;
101 
104 
105 private:
106  template<typename T> void MakeKernel( const RadiusType & radius, T & kernel )
107  {
108  kernel.SetRadius( radius );
109  for( typename T::Iterator kit=kernel.Begin(); kit != kernel.End(); kit++ )
110  {
111  *kit = 1;
112  }
113  }
114 
115  void MakeKernel( const RadiusType & radius, FlatKernelType & kernel )
116  {
117  // set up a decomposable box structuring element which is
118  // much efficient with van Herk / Gil Werman filters
119  kernel = FlatKernelType::Box( radius );
120  assert( kernel.GetDecomposable() );
121  }
122 };
123 }
124 
125 #ifndef ITK_MANUAL_INSTANTIATION
126 #include "itkKernelImageFilter.hxx"
127 #endif
128 
129 #endif
typename TInputImage::SizeType RadiusType
void MakeKernel(const RadiusType &radius, FlatKernelType &kernel)
void MakeKernel(const RadiusType &radius, T &kernel)
unsigned long SizeValueType
Definition: itkIntTypes.h:83
typename TInputImage::IndexType IndexType
typename TOutputImage::PixelType OutputPixelType
typename TInputImage::RegionType RegionType
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
void SetRadius(const SizeValueType &radius) override
Base class for all process objects that output image data.
typename TInputImage::OffsetType OffsetType
typename TInputImage::SizeType SizeType
TOutputImage OutputImageType
typename TInputImage::PixelType InputPixelType
A base class for all the filters working on an arbitrary shaped neighborhood.
A base class for all the filters working on a box neighborhood.
A class to support a variety of flat structuring elements, including versions created by decompositio...
Control indentation during Print() invocation.
Definition: itkIndent.h:49