GaussianInterpolateImageFunction.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_GaussianInterpolateImageFunction_H
22 #define MIRTK_GaussianInterpolateImageFunction_H
23 
24 #include "mirtk/BaseImage.h"
25 #include "mirtk/InterpolateImageFunction.h"
26 
27 
28 namespace mirtk {
29 
30 
31 /**
32  * Gaussian interpolation of generic image
33  */
34 template <class TImage>
36 : public GenericInterpolateImageFunction<TImage>
37 {
38  mirtkGenericInterpolatorMacro(
40  Interpolation_Gaussian
41  );
42 
43  // ---------------------------------------------------------------------------
44  // Attributes
45 
46  /// Gaussian standard deviation (in mm)
47  mirtkPublicAttributeMacro(double, Sigma);
48 
49 protected:
50 
51  /// Filter radius in x dimension
52  double _RadiusX;
53 
54  /// Filter radius in y dimension
55  double _RadiusY;
56 
57  /// Filter radius in z dimension
58  double _RadiusZ;
59 
60  /// Filter radius in t dimension
61  double _RadiusT;
62 
63  /// Voxel size of input image
64  double _dx, _dy, _dz, _dt;
65 
66  // ---------------------------------------------------------------------------
67  // Construction/Destruction
68 
69 public:
70 
71  /// Default constructor
73 
74  /// Initialize interpolation function
75  virtual void Initialize(bool = false);
76 
77  // ---------------------------------------------------------------------------
78  // Domain checks
79 
80  /// Returns interval of discrete image indices whose values are needed for
81  /// interpolation of the image value at a given continuous coordinate
82  virtual void BoundingInterval(double, int &, int &) const;
83 
84  /// Returns discrete boundaries of local 2D image region needed for interpolation
85  virtual void BoundingBox(double, double, int &, int &,
86  int &, int &) const;
87 
88  /// Returns discrete boundaries of local 3D image region needed for interpolation
89  virtual void BoundingBox(double, double, double, int &, int &, int &,
90  int &, int &, int &) const;
91 
92  /// Returns discrete boundaries of local 4D image region needed for interpolation
93  virtual void BoundingBox(double, double, double, double,
94  int &, int &, int &, int &,
95  int &, int &, int &, int &) const;
96 
97  // ---------------------------------------------------------------------------
98  // Evaluation
99 
100  /// Get value of given 2D image at arbitrary location (in pixels)
101  ///
102  /// This function is used to interpolate the image value at arbitrary
103  /// locations when no extrapolator was set.
104  VoxelType Get2D(double, double, double = 0, double = 0) const;
105 
106  /// Get value of given 2D image at arbitrary location (in pixels)
107  ///
108  /// This function is used to only interpolate foreground image values.
109  /// If fully outside the foreground region, the _DefaultValue is returned.
110  VoxelType GetWithPadding2D(double, double, double = 0, double = 0) const;
111 
112  /// Get value of given 2D image at arbitrary location (in pixels)
113  ///
114  /// If the location is inside the finite domain of the image, an actual image
115  /// instance can be passed as first argument directly such as an instance of
116  /// GenericImage. Otherwise, an image function which extends the finite
117  /// image domain to an infinite lattice is needed, i.e., an instance of a
118  /// subclass of ExtrapolateImageFunction.
119  template <class TOtherImage> typename TOtherImage::VoxelType
120  Get2D(const TOtherImage *, double, double, double = 0, double = 0) const;
121 
122  /// Get value of given 2D image at arbitrary location (in pixels)
123  ///
124  /// This function is used to only interpolate foreground image values.
125  /// If fully outside the foreground region, the _DefaultValue is returned.
126  ///
127  /// If the location is inside the finite domain of the image, an actual image
128  /// instance can be passed as first argument directly such as an instance of
129  /// GenericImage. Otherwise, an image function which extends the finite
130  /// image domain to an infinite lattice is needed, i.e., an instance of a
131  /// subclass of ExtrapolateImageFunction.
132  template <class TOtherImage> typename TOtherImage::VoxelType
133  GetWithPadding2D(const TOtherImage *, double, double, double = 0, double = 0) const;
134 
135  /// Get value of given 3D image at arbitrary location (in pixels)
136  ///
137  /// This function is used to interpolate the image value at arbitrary
138  /// locations when no extrapolator was set.
139  VoxelType Get3D(double, double, double = 0, double = 0) const;
140 
141  /// Get value of given 3D image at arbitrary location (in pixels)
142  ///
143  /// This function is used to only interpolate foreground image values.
144  /// If fully outside the foreground region, the _DefaultValue is returned.
145  VoxelType GetWithPadding3D(double, double, double = 0, double = 0) const;
146 
147  /// Get value of given 3D image at arbitrary location (in pixels)
148  ///
149  /// If the location is inside the finite domain of the image, an actual image
150  /// instance can be passed as first argument directly such as an instance of
151  /// GenericImage. Otherwise, an image function which extends the finite
152  /// image domain to an infinite lattice is needed, i.e., an instance of a
153  /// subclass of ExtrapolateImageFunction.
154  template <class TOtherImage> typename TOtherImage::VoxelType
155  Get3D(const TOtherImage *, double, double, double = 0, double = 0) const;
156 
157  /// Get value of given 3D image at arbitrary location (in pixels)
158  ///
159  /// This function is used to only interpolate foreground image values.
160  /// If fully outside the foreground region, the _DefaultValue is returned.
161  ///
162  /// If the location is inside the finite domain of the image, an actual image
163  /// instance can be passed as first argument directly such as an instance of
164  /// GenericImage. Otherwise, an image function which extends the finite
165  /// image domain to an infinite lattice is needed, i.e., an instance of a
166  /// subclass of ExtrapolateImageFunction.
167  template <class TOtherImage> typename TOtherImage::VoxelType
168  GetWithPadding3D(const TOtherImage *, double, double, double = 0, double = 0) const;
169 
170  /// Get value of given 4D image at arbitrary location (in pixels)
171  ///
172  /// This function is used to interpolate the image value at arbitrary
173  /// locations when no extrapolator was set.
174  VoxelType Get4D(double, double, double = 0, double = 0) const;
175 
176  /// Get value of given 4D image at arbitrary location (in pixels)
177  ///
178  /// This function is used to only interpolate foreground image values.
179  /// If fully outside the foreground region, the _DefaultValue is returned.
180  VoxelType GetWithPadding4D(double, double, double = 0, double = 0) const;
181 
182  /// Get value of given 4D image at arbitrary location (in pixels)
183  ///
184  /// If the location is inside the finite domain of the image, an actual image
185  /// instance can be passed as first argument directly such as an instance of
186  /// GenericImage. Otherwise, an image function which extends the finite
187  /// image domain to an infinite lattice is needed, i.e., an instance of a
188  /// subclass of ExtrapolateImageFunction.
189  template <class TOtherImage> typename TOtherImage::VoxelType
190  Get4D(const TOtherImage *, double, double, double = 0, double = 0) const;
191 
192  /// Get value of given 4D image at arbitrary location (in pixels)
193  ///
194  /// This function is used to only interpolate foreground image values.
195  /// If fully outside the foreground region, the _DefaultValue is returned.
196  ///
197  /// If the location is inside the finite domain of the image, an actual image
198  /// instance can be passed as first argument directly such as an instance of
199  /// GenericImage. Otherwise, an image function which extends the finite
200  /// image domain to an infinite lattice is needed, i.e., an instance of a
201  /// subclass of ExtrapolateImageFunction.
202  template <class TOtherImage> typename TOtherImage::VoxelType
203  GetWithPadding4D(const TOtherImage *, double, double, double = 0, double = 0) const;
204 
205  /// Get value of given image at arbitrary location (in pixels)
206  ///
207  /// This function is used to interpolate the image value at arbitrary
208  /// locations when no extrapolator was set.
209  VoxelType Get(double, double, double = 0, double = 0) const;
210 
211  /// Get value of given image at arbitrary location (in pixels)
212  ///
213  /// This function is used to only interpolate foreground image values.
214  /// If fully outside the foreground region, the _DefaultValue is returned.
215  virtual VoxelType GetWithPadding(double, double, double = 0, double = 0) const;
216 
217  /// Get value of given image at arbitrary location (in pixels)
218  ///
219  /// If the location is inside the finite domain of the image, an actual image
220  /// instance can be passed as first argument directly such as an instance of
221  /// GenericImage. Otherwise, an image function which extends the finite
222  /// image domain to an infinite lattice is needed, i.e., an instance of a
223  /// subclass of ExtrapolateImageFunction.
224  template <class TOtherImage> typename TOtherImage::VoxelType
225  Get(const TOtherImage *, double, double, double = 0, double = 0) const;
226 
227  /// Get value of given image at arbitrary location (in pixels)
228  ///
229  /// This function is used to only interpolate foreground image values.
230  /// If fully outside the foreground region, the _DefaultValue is returned.
231  ///
232  /// If the location is inside the finite domain of the image, an actual image
233  /// instance can be passed as first argument directly such as an instance of
234  /// GenericImage. Otherwise, an image function which extends the finite
235  /// image domain to an infinite lattice is needed, i.e., an instance of a
236  /// subclass of ExtrapolateImageFunction.
237  template <class TOtherImage> typename TOtherImage::VoxelType
238  GetWithPadding(const TOtherImage *, double, double, double = 0, double = 0) const;
239 
240  /// Evaluate generic image without handling boundary conditions
241  ///
242  /// This version is faster than EvaluateOutside, but is only defined inside
243  /// the domain for which all image values required for interpolation are
244  /// defined and thus require no extrapolation of the finite image.
245  virtual VoxelType GetInside(double, double, double = 0, double = 0) const;
246 
247  /// Evaluate generic image at an arbitrary location (in pixels)
248  virtual VoxelType GetOutside(double, double, double = 0, double = 0) const;
249 
250  /// Evaluate generic image without handling boundary conditions
251  ///
252  /// If the location is partially inside the foreground region of the image,
253  /// only the foreground values are interpolated. Otherwise, the _DefaultValue
254  /// is returned.
255  ///
256  /// This version is faster than GetWithPaddingOutside, but is only defined
257  /// inside the domain for which all image values required for interpolation
258  /// are defined and thus require no extrapolation of the finite image.
259  virtual VoxelType GetWithPaddingInside(double, double, double = 0, double = 0) const;
260 
261  /// Evaluate generic image at an arbitrary location (in pixels)
262  ///
263  /// If the location is partially inside the foreground region of the image,
264  /// only the foreground values are interpolated. Otherwise, the _DefaultValue
265  /// is returned.
266  virtual VoxelType GetWithPaddingOutside(double, double, double = 0, double = 0) const;
267 
268 };
269 
270 
271 /**
272  * Gaussian interpolation of any scalar image
273  */
275 : public GenericGaussianInterpolateImageFunction<BaseImage>
276 {
277  mirtkObjectMacro(GaussianInterpolateImageFunction);
278 
279 public:
280 
281  /// Constructor
283  :
285  {}
286 
287 };
288 
289 
290 } // namespace mirtk
291 
292 #endif // MIRTK_GaussianInterpolateImageFunction_H
virtual VoxelType GetWithPadding(double, double, double=0, double=0) const
VoxelType GetWithPadding2D(double, double, double=0, double=0) const
virtual VoxelType GetWithPaddingInside(double, double, double=0, double=0) const
VoxelType Get(double, double, double=0, double=0) const
virtual void BoundingBox(double, double, int &, int &, int &, int &) const
Returns discrete boundaries of local 2D image region needed for interpolation.
VoxelType Get2D(double, double, double=0, double=0) const
virtual VoxelType GetOutside(double, double, double=0, double=0) const
Evaluate generic image at an arbitrary location (in pixels)
Definition: IOConfig.h:41
VoxelType GetWithPadding4D(double, double, double=0, double=0) const
virtual VoxelType GetWithPaddingOutside(double, double, double=0, double=0) const
virtual void BoundingInterval(double, int &, int &) const
VoxelType Get4D(double, double, double=0, double=0) const
VoxelType GetWithPadding3D(double, double, double=0, double=0) const
GaussianInterpolateImageFunction(double sigma=1.0)
Constructor.
GenericGaussianInterpolateImageFunction(double=1.0)
Default constructor.
VoxelType Get3D(double, double, double=0, double=0) const
virtual VoxelType GetInside(double, double, double=0, double=0) const