GradientImageFilter.h
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2008-2015 Imperial College London
5  * Copyright 2008-2013 Daniel Rueckert, Julia Schnabel
6  * Copyright 2013-2015 Andreas Schuh
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef MIRTK_GradientImageFilter_H
22 #define MIRTK_GradientImageFilter_H
23 
24 #include "mirtk/ImageToImage.h"
25 
26 
27 namespace mirtk {
28 
29 
30 /**
31  * Class for calculating the gradient of an image.
32  *
33  * The class provides an interface to calculating the gradient in the
34  * x, y and z directions. It also can process vector-valued input images,
35  * where each vector component is treated separately. If the output for each
36  * component is a 3D gradient vector, the output image contains first the
37  * gradient vector for the first input component, then the gradient vector
38  * of the second component, and so on. In case of a scalar gradient output
39  * such as the gradient vector magnitude, the output image has the same
40  * number of components (t dimension) as the input image.
41  */
42 template <class TVoxel>
43 class GradientImageFilter : public ImageToImage<TVoxel>
44 {
45  mirtkImageFilterMacro(GradientImageFilter, TVoxel);
46 
47  // ---------------------------------------------------------------------------
48  // Types
49 
50 public:
51 
52  /// Type of image gradient to compute
53  enum GradientType {
54  GRADIENT_X,
55  GRADIENT_Y,
56  GRADIENT_Z,
57  GRADIENT_MAGNITUDE,
58  GRADIENT_VECTOR,
59  NORMALISED_GRADIENT_VECTOR,
60  GRADIENT_DOT_PRODUCT,
61  NUM_GRADIENT_TYPES // Keep as last enumeration entry!
62  };
63 
64  // ---------------------------------------------------------------------------
65  // Attributes
66 
67 protected:
68 
69  /// Type of gradient
71 
72  /// Whether to return gradient in mm or voxel units
73  mirtkPublicAttributeMacro(bool, UseVoxelSize);
74 
75  /// Whether to return gradient in world orientation
76  mirtkPublicAttributeMacro(bool, UseOrientation);
77 
78  /// Padding value
79  mirtkPublicAttributeMacro(double, PaddingValue);
80 
81  // ---------------------------------------------------------------------------
82  // Construction/Destruction
83 
84 public:
85 
86  /// Constructor
87  GradientImageFilter(GradientType type = GRADIENT_MAGNITUDE);
88 
89  // ---------------------------------------------------------------------------
90  // Execution
91 
92  /// Run the convolution filter
93  virtual void Run();
94 
95 protected:
96 
97  /// Initialize filter after inputs and parameters are set
98  virtual void Initialize();
99 
100  /// Finalize filter execution
101  virtual void Finalize();
102 
103 };
104 
105 
106 } // namespace mirtk
107 
108 #endif // MIRTK_GradientImageFilter_H
virtual void Initialize()
Initialize filter after inputs and parameters are set.
GradientImageFilter(GradientType type=GRADIENT_MAGNITUDE)
Constructor.
GradientType
Type of image gradient to compute.
mirtkPublicAttributeMacro(GradientType, Type)
Type of gradient.
Definition: IOConfig.h:41
virtual void Finalize()
Finalize filter execution.
virtual void Run()
Run the convolution filter.