CityBlockDistanceTransform.h
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2011-2016 Imperial College London
5  * Copyright 2011 Paul Aljabar
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_CityBlockDistanceTransform_H
21 #define MIRTK_CityBlockDistanceTransform_H
22 
23 #include "mirtk/ImageToImage.h"
24 
25 #include "mirtk/NeighborhoodOffsets.h"
26 
27 
28 namespace mirtk {
29 
30 
31 /**
32  * City block image distance transform
33  *
34  * Find the City Block (Manhattan, L1) distance for all object voxels in an
35  * image from the boundary. Object voxels have a value greater than zero and
36  * background voxels are the rest. The distance map is initialised to zero.
37  * In each iteration, the distance map is incremented by 1 for all object
38  * voxels. The border voxels are removed and the the next iteration starts.
39  * If any dimension is a singleton, a 2D version is applied.
40  */
41 template <class TVoxel>
43 {
44  mirtkInPlaceImageFilterMacro(CityBlockDistanceTransform, TVoxel);
45 
46  // ---------------------------------------------------------------------------
47  // Types
48 
49  /// In the 2D case, a flip may be necessary so that the singleton dimension
50  /// is the z-direction. This makes processing easier.
51  enum FlipType { FlipNone, FlipXY, FlipXZ, FlipYZ };
52 
53  // ---------------------------------------------------------------------------
54  // Attriubutes
55 
56  /// Storage for the object voxels that can be updated.
57  GreyImage _data;
58 
59  /// List of voxel offsets of the 6 neighbourhood of a voxel. Enables checking to
60  /// see if there is a face-neighbour labelled background during each iteration.
61  NeighborhoodOffsets _offsets;
62 
63  FlipType _flipType;
64 
65  // ---------------------------------------------------------------------------
66  // Construction/Destruction
67 
68 public:
69 
70  /// Default constructor
72 
73  /// Destructor
75 
76  // ---------------------------------------------------------------------------
77  // Execution
78 
79  /// Run distance transform
80  virtual void Run();
81 
82 protected:
83 
84  /// Run distance transform in 2D
85  virtual void Run2D();
86 
87  /// Run distance transform in 3D
88  virtual void Run3D();
89 
90  /// Initialize the filter
91  virtual void Initialize();
92 
93  /// Initialize the filter
94  virtual void Initialize2D();
95 
96  /// Initialize the filter
97  virtual void Initialize3D();
98 
99  /// Finalize the filter
100  virtual void Finalize();
101 
102 };
103 
104 
105 } // namespace mirtk
106 
107 #endif // MIRTK_CityBlockDistanceTransform_H
virtual void Run3D()
Run distance transform in 3D.
virtual void Finalize()
Finalize the filter.
virtual void Run()
Run distance transform.
Definition: IOConfig.h:41
virtual void Initialize()
Initialize the filter.
virtual void Run2D()
Run distance transform in 2D.
virtual void Initialize2D()
Initialize the filter.
CityBlockDistanceTransform()
Default constructor.
virtual void Initialize3D()
Initialize the filter.