GradientFieldSimilarity.h
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2013-2015 Imperial College London
5  * Copyright 2013-2015 Stefan Pszczolkowski Parraguez, 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_GradientFieldSimilarity_H
21 #define MIRTK_GradientFieldSimilarity_H
22 
23 #include "mirtk/ImageSimilarity.h"
24 
25 
26 namespace mirtk {
27 
28 
29 /**
30  * Base class for gradient field similarity measures
31  *
32  * Subclasses of this image similarity measure evaluate similarity of two images
33  * based on their intensity gradient.
34  */
36 {
37  mirtkObjectMacro(GradientFieldSimilarity);
38 
39  // ---------------------------------------------------------------------------
40  // Attributes
41 
42  /// Noise parameter for target image
43  mirtkPublicAttributeMacro(bool, IgnoreJacobianGradientWrtDOFs);
44 
45  /// Transformed gradient of the target image
46  /// Used only if the target image is being transformed
47  mirtkAttributeMacro(GenericImage<RegisteredImage::VoxelType>, TargetTransformedGradient);
48 
49  /// Transformed gradient of the source image
50  /// Used only if the source image is being transformed
51  mirtkAttributeMacro(GenericImage<RegisteredImage::VoxelType>, SourceTransformedGradient);
52 
53  // ---------------------------------------------------------------------------
54  // Construction/Destruction
55 
56 protected:
57 
58  /// Constructor
59  GradientFieldSimilarity(const char * = "", double = 1.0);
60 
61  /// Copy constructor
63 
64  /// Destructor
65  virtual ~GradientFieldSimilarity();
66 
67  // ---------------------------------------------------------------------------
68  // Parameters
69 
70 public:
71 
72  /// Set parameter value from string
73  virtual bool Set(const char *, const char *);
74 
75  // Import other overloads
77 
78  /// Get parameter name/value map
79  virtual ParameterList Parameter() const;
80 
81 protected:
82 
83  // ---------------------------------------------------------------------------
84  // Initialization
85 
86  /// Initialize similarity measure once input and parameters have been set
87  /// \param[in] domain Image domain on which the similarity is evaluated.
88  virtual void InitializeInput(const ImageAttributes &domain);
89 
90  // ---------------------------------------------------------------------------
91  // Evaluation
92 
93  /// Convert non-parametric similarity gradient into gradient
94  /// w.r.t transformation parameters
95  ///
96  /// This function calls Transformation::ParametricGradient of the
97  /// transformation to apply the chain rule in order to obtain the similarity
98  /// gradient w.r.t the transformation parameters. It adds the weighted gradient
99  /// to the final registration energy gradient.
100  ///
101  /// \param[in] image Transformed image.
102  /// \param[in] np_gradient Voxel-wise non-parametric gradient.
103  /// \param[inout] gradient Gradient to which the computed parametric gradient
104  /// is added, after multiplication by the given \p weight.
105  /// \param[in] weight Weight of image similarity.
106  virtual void ParametricGradient(const RegisteredImage *image,
107  GradientImageType *np_gradient,
108  double *gradient,
109  double weight);
110 
111  /// Update moving input image(s) and internal state of similarity measure
112  virtual void Update(bool = true);
113 
114  /// Reorient transformed image gradient according to dI(y)/dy * dy/dx
115  void ReorientGradient(RegisteredImage *, bool = false);
116 
117  /// Multiply similarity gradient by 2nd order derivatives of transformed image
118  ///
119  /// \param[in] image Transformed image
120  /// \param[in,out] gradient Input must be the gradient of the image similarity
121  /// w.r.t. the transformed \p image gradient. Output is
122  /// the voxel-wise gradient of the similarity w.r.t. T(x).
123  void MultiplyByImageHessian(const RegisteredImage *image,
124  GradientImageType *gradient);
125 
126 };
127 
128 
129 } // namespace mirtk
130 
131 #endif // MIRTK_GradientFieldSimilarity_H
void ReorientGradient(RegisteredImage *, bool=false)
Reorient transformed image gradient according to dI(y)/dy * dy/dx.
Array< Pair< string, string > > ParameterList
Ordered list of parameter name/value pairs.
Definition: Object.h:38
virtual void Update(bool=true)
Update moving input image(s) and internal state of similarity measure.
void MultiplyByImageHessian(const RegisteredImage *image, GradientImageType *gradient)
GradientFieldSimilarity(const char *="", double=1.0)
Constructor.
Definition: IOConfig.h:41
virtual ParameterList Parameter() const
Get parameter key/value as string map.
virtual void ParametricGradient(const RegisteredImage *image, GradientImageType *np_gradient, double *gradient, double weight)
virtual bool Set(const char *, const char *)
Set parameter value from string.
virtual ~GradientFieldSimilarity()
Destructor.
virtual ParameterList Parameter() const
Get parameter name/value map.
virtual void InitializeInput(const ImageAttributes &domain)