Dilation.h
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2008-2015 Imperial College London
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #ifndef MIRTK_Dilation_H
20 #define MIRTK_Dilation_H
21 
22 #include "mirtk/ImageToImage.h"
23 
24 #include "mirtk/Assert.h"
25 #include "mirtk/NeighborhoodOffsets.h"
26 
27 
28 namespace mirtk {
29 
30 
31 /**
32  * morphological erosion of images.
33  */
34 template <class TVoxel>
35 class Dilation : public ImageToImage<TVoxel>
36 {
37  mirtkImageFilterMacro(Dilation, TVoxel);
38 
39  /// What connectivity to assume when running the filter.
40  mirtkPublicAttributeMacro(ConnectivityType, Connectivity);
41 
42  /// List of voxel offsets of the neighborhood
43  mirtkAttributeMacro(NeighborhoodOffsets, Offsets);
44 
45 public:
46 
47  /// Constructor
48  Dilation();
49 
50  /// Destructor
51  virtual ~Dilation();
52 
53  /// Run erosion
54  virtual void Run();
55 
56 protected:
57 
58  /// Initialize the filter
59  virtual void Initialize();
60 
61 };
62 
63 
64 // -----------------------------------------------------------------------------
65 template <class TVoxel>
66 void Dilate(BaseImage *image, int iterations, ConnectivityType connectivity)
67 {
68  GenericImage<TVoxel> * const im = dynamic_cast<GenericImage<TVoxel> *>(image);
69  mirtkAssert(im != nullptr, "template function called with correct type");
70  Dilation<TVoxel> dilation;
71  dilation.Connectivity(connectivity);
72  dilation.Input (im);
73  dilation.Output(im);
74  for (int i = 0; i < iterations; ++i) dilation.Run();
75 }
76 
77 
78 } // namespace mirtk
79 
80 #endif // MIRTK_Dilation_H
virtual ~Dilation()
Destructor.
Dilation()
Constructor.
virtual void Run()
Run erosion.
virtual void Initialize()
Initialize the filter.
Definition: IOConfig.h:41
ConnectivityType
Type of image connectivity, i.e., number of neighbors for each voxel.