ImageTransformation.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_ImageTransformation_H
22 #define MIRTK_ImageTransformation_H
23 
24 #include "mirtk/Transformation.h"
25 #include "mirtk/GenericImage.h"
26 #include "mirtk/InterpolateImageFunction.h"
27 
28 
29 namespace mirtk {
30 
31 
32 /** Image used to cache displacements
33  *
34  * \todo Use Vector3D<double> as voxel type to enable the caching of
35  * a 4D displacement field which is generated by a 4D transformation
36  * or a 3D SV FFD integrated over multiple time intervals.
37  */
39 {
40  mirtkObjectMacro(ImageTransformationCache);
41 
42  /// Whether the cache requires an update
43  mirtkPublicAttributeMacro(bool, Modified);
44 
45 public:
46 
47  /// Constructor
48  ImageTransformationCache() : _Modified(true) {}
49 
50  /// Constructor
52  :
53  RealImage(attr, 3), _Modified(true)
54  {}
55 
56  /// Destructor
58 };
59 
60 
61 /**
62  * Filter for image transformations.
63  *
64  * This class implements an image filter which takes an input image and a
65  * transformation and computes the corresponding output image. The output
66  * image is calculated by looping over the voxel locations and calculating
67  * the corresponding voxel locations in the input image. The intensity of
68  * the voxels of the output image is by interpolation from the input image.
69  * Note, that the transformation is assumed to map the input image into the
70  * output image and is therefore inverted during the execution of the filter.
71  * All calculations are carried out using world coordinates rather than image
72  * coordinates.
73  */
75 {
76  mirtkObjectMacro(ImageTransformation);
77 
78  // ---------------------------------------------------------------------------
79  // Attributes
80 
81  /// Untransformed input image
82  mirtkPublicAggregateMacro(const BaseImage, Input);
83 
84  /// Transformed output image (grid)
85  mirtkPublicAggregateMacro(BaseImage, Output);
86 
87  /// Image transformation
88  mirtkReadOnlyAggregateMacro(const class Transformation, Transformation);
89 
90  /// Image interpolator
91  mirtkPublicAggregateMacro(InterpolateImageFunction, Interpolator);
92 
93  /// Padding value in target (voxels in the target image with this
94  /// value will be ignored)
95  mirtkPublicAttributeMacro(double, TargetPaddingValue);
96 
97  /// Padding value in source (voxels outside the source image will
98  /// be set to this value)
99  mirtkPublicAttributeMacro(double, SourcePaddingValue);
100 
101  /// Scale factor for intensities in transformed image
102  mirtkPublicAttributeMacro(double, ScaleFactor);
103 
104  /// Offset for intensities in transformed image
105  mirtkPublicAttributeMacro(double, Offset);
106 
107  /// Temporal offset of input image (in addition to input _torigin)
108  mirtkPublicAttributeMacro(double, InputTimeOffset);
109 
110  /// Temporal offset of output image (in addition to output _torigin)
111  mirtkPublicAttributeMacro(double, OutputTimeOffset);
112 
113  /// Flag whether to invert transformation
114  mirtkReadOnlyAttributeMacro(bool, Invert);
115 
116  /// Flag whether input is 2D
117  mirtkPublicAttributeMacro(bool, TwoD);
118 
119  /// Cached displacements
120  mirtkReadOnlyAggregateMacro(ImageTransformationCache, Cache);
121 
122  /// Whether the cache was allocated by this instance
123  mirtkAttributeMacro(bool, CacheOwner);
124 
125  /// Interpolation mode to use for interpolating cached displacements
126  mirtkPublicAttributeMacro(InterpolationMode, CacheInterpolation);
127 
128  /// Extrapolation mode to use when interpolating cached displacements
129  mirtkPublicAttributeMacro(ExtrapolationMode, CacheExtrapolation);
130 
131  /// Interpolator for cached displacements
132  mirtkComponentMacro(InterpolateImageFunction, DisplacementField);
133 
134  /// Number of points for which the required inverse transformation was invalid
135  mirtkReadOnlyAttributeMacro(int, NumberOfSingularPoints);
136 
137  // ---------------------------------------------------------------------------
138  // Custom setters
139 public:
140 
141  /// Set transformation
142  virtual void Transformation(const class Transformation *);
143 
144  /// Set transformation cache
145  virtual void Cache(ImageTransformationCache *);
146 
147  /// Enable/disable inversion of transformation
148  virtual void Invert(bool);
149 
150  // ---------------------------------------------------------------------------
151  // Construction/Destruction
152 public:
153 
154  /// Constructor
156 
157  /// Destructor
158  virtual ~ImageTransformation();
159 
160  // ---------------------------------------------------------------------------
161  // Execution
162 
163  /// Resample transformed input image on output image grid
164  virtual void Run();
165 
166 protected:
167 
168  /// Initialize filter
169  virtual void Initialize();
170 
171 };
172 
173 
174 } // namespace mirtk
175 
176 #endif // MIRTK_ImageTransformation_H
InterpolationMode
Image interpolation modes.
Definition: IOConfig.h:41
ImageTransformationCache(const ImageAttributes &attr)
Constructor.
virtual ~ImageTransformationCache()
Destructor.
ExtrapolationMode
Image extrapolation modes.
virtual void Initialize()
Initialize a previously allocated image.