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