SincInterpolateImageFunction.h
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2013-2015 Imperial College London
5  * Copyright 2013-2015 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_SincInterpolateImageFunction_H
21 #define MIRTK_SincInterpolateImageFunction_H
22 
23 #include "mirtk/InterpolateImageFunction.h"
24 #include "mirtk/BaseImage.h"
25 
26 
27 namespace mirtk {
28 
29 
30 // Interpolation kernel type
31 template <class T> class Sinc;
32 
33 
34 /**
35  * Sinc interpolation of generic image
36  */
37 template <class TImage>
39 : public GenericInterpolateImageFunction<TImage>
40 {
41  mirtkGenericInterpolatorMacro(
43  Interpolation_Sinc
44  );
45 
46  // ---------------------------------------------------------------------------
47  // Types
48 
49 public:
50 
51  /// Sinc interpolation kernel function
52  typedef Sinc<Real> Kernel;
53 
54  // ---------------------------------------------------------------------------
55  // Attributes
56 
57  /// Epsilon range within which to use nearest neighbor interpolation instead
58  mirtkPublicAttributeMacro(double, Epsilon);
59 
60  // ---------------------------------------------------------------------------
61  // Construction/Destruction
62 
63 public:
64 
65  /// Default constructor
67 
68  /// Initialize interpolation function
69  virtual void Initialize(bool = false);
70 
71  // ---------------------------------------------------------------------------
72  // Domain checks
73 
74  /// Returns interval of discrete image indices whose values are needed for
75  /// interpolation of the image value at a given continuous coordinate
76  virtual void BoundingInterval(double, int &, int &) const;
77 
78  // ---------------------------------------------------------------------------
79  // Evaluation
80 
81  /// Get value of given 2D image at arbitrary location (in pixels)
82  ///
83  /// This function is used to interpolate the image value at arbitrary
84  /// locations when no extrapolator was set.
85  VoxelType Get2D(double, double, double = 0, double = 0) const;
86 
87  /// Get value of given 2D image at arbitrary location (in pixels)
88  ///
89  /// This function is used to only interpolate foreground image values.
90  /// If fully outside the foreground region, the _DefaultValue is returned.
91  VoxelType GetWithPadding2D(double, double, double = 0, double = 0) const;
92 
93  /// Get value of given 2D image at arbitrary location (in pixels)
94  ///
95  /// If the location is inside the finite domain of the image, an actual image
96  /// instance can be passed as first argument directly such as an instance of
97  /// GenericImage. Otherwise, an image function which extends the finite
98  /// image domain to an infinite lattice is needed, i.e., an instance of a
99  /// subclass of ExtrapolateImageFunction.
100  template <class TOtherImage> typename TOtherImage::VoxelType
101  Get2D(const TOtherImage *, double, double, double = 0, double = 0) const;
102 
103  /// Get value of given 2D image at arbitrary location (in pixels)
104  ///
105  /// This function is used to only interpolate foreground image values.
106  /// If fully outside the foreground region, the _DefaultValue is returned.
107  ///
108  /// If the location is inside the finite domain of the image, an actual image
109  /// instance can be passed as first argument directly such as an instance of
110  /// GenericImage. Otherwise, an image function which extends the finite
111  /// image domain to an infinite lattice is needed, i.e., an instance of a
112  /// subclass of ExtrapolateImageFunction.
113  template <class TOtherImage> typename TOtherImage::VoxelType
114  GetWithPadding2D(const TOtherImage *, double, double, double = 0, double = 0) const;
115 
116  /// Get value of given 3D image at arbitrary location (in pixels)
117  ///
118  /// This function is used to interpolate the image value at arbitrary
119  /// locations when no extrapolator was set.
120  VoxelType Get3D(double, double, double = 0, double = 0) const;
121 
122  /// Get value of given 3D 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  VoxelType GetWithPadding3D(double, double, double = 0, double = 0) const;
127 
128  /// Get value of given 3D image at arbitrary location (in pixels)
129  ///
130  /// If the location is inside the finite domain of the image, an actual image
131  /// instance can be passed as first argument directly such as an instance of
132  /// GenericImage. Otherwise, an image function which extends the finite
133  /// image domain to an infinite lattice is needed, i.e., an instance of a
134  /// subclass of ExtrapolateImageFunction.
135  template <class TOtherImage> typename TOtherImage::VoxelType
136  Get3D(const TOtherImage *, double, double, double = 0, double = 0) const;
137 
138  /// Get value of given 3D image at arbitrary location (in pixels)
139  ///
140  /// This function is used to only interpolate foreground image values.
141  /// If fully outside the foreground region, the _DefaultValue is returned.
142  ///
143  /// If the location is inside the finite domain of the image, an actual image
144  /// instance can be passed as first argument directly such as an instance of
145  /// GenericImage. Otherwise, an image function which extends the finite
146  /// image domain to an infinite lattice is needed, i.e., an instance of a
147  /// subclass of ExtrapolateImageFunction.
148  template <class TOtherImage> typename TOtherImage::VoxelType
149  GetWithPadding3D(const TOtherImage *, double, double, double = 0, double = 0) const;
150 
151  /// Get value of given 4D image at arbitrary location (in pixels)
152  ///
153  /// This function is used to interpolate the image value at arbitrary
154  /// locations when no extrapolator was set.
155  VoxelType Get4D(double, double, double = 0, double = 0) const;
156 
157  /// Get value of given 4D 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  VoxelType GetWithPadding4D(double, double, double = 0, double = 0) const;
162 
163  /// Get value of given 4D image at arbitrary location (in pixels)
164  ///
165  /// If the location is inside the finite domain of the image, an actual image
166  /// instance can be passed as first argument directly such as an instance of
167  /// GenericImage. Otherwise, an image function which extends the finite
168  /// image domain to an infinite lattice is needed, i.e., an instance of a
169  /// subclass of ExtrapolateImageFunction.
170  template <class TOtherImage> typename TOtherImage::VoxelType
171  Get4D(const TOtherImage *, double, double, double = 0, double = 0) const;
172 
173  /// Get value of given 4D image at arbitrary location (in pixels)
174  ///
175  /// This function is used to only interpolate foreground image values.
176  /// If fully outside the foreground region, the _DefaultValue is returned.
177  ///
178  /// If the location is inside the finite domain of the image, an actual image
179  /// instance can be passed as first argument directly such as an instance of
180  /// GenericImage. Otherwise, an image function which extends the finite
181  /// image domain to an infinite lattice is needed, i.e., an instance of a
182  /// subclass of ExtrapolateImageFunction.
183  template <class TOtherImage> typename TOtherImage::VoxelType
184  GetWithPadding4D(const TOtherImage *, double, double, double = 0, double = 0) const;
185 
186  /// Get value of given image at arbitrary location (in pixels)
187  ///
188  /// This function is used to interpolate the image value at arbitrary
189  /// locations when no extrapolator was set.
190  VoxelType Get(double, double, double = 0, double = 0) const;
191 
192  /// Get value of given 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  virtual VoxelType GetWithPadding(double, double, double = 0, double = 0) const;
197 
198  /// Get value of given image at arbitrary location (in pixels)
199  ///
200  /// If the location is inside the finite domain of the image, an actual image
201  /// instance can be passed as first argument directly such as an instance of
202  /// GenericImage. Otherwise, an image function which extends the finite
203  /// image domain to an infinite lattice is needed, i.e., an instance of a
204  /// subclass of ExtrapolateImageFunction.
205  template <class TOtherImage> typename TOtherImage::VoxelType
206  Get(const TOtherImage *, double, double, double = 0, double = 0) const;
207 
208  /// Get value of given image at arbitrary location (in pixels)
209  ///
210  /// This function is used to only interpolate foreground image values.
211  /// If fully outside the foreground region, the _DefaultValue is returned.
212  ///
213  /// If the location is inside the finite domain of the image, an actual image
214  /// instance can be passed as first argument directly such as an instance of
215  /// GenericImage. Otherwise, an image function which extends the finite
216  /// image domain to an infinite lattice is needed, i.e., an instance of a
217  /// subclass of ExtrapolateImageFunction.
218  template <class TOtherImage> typename TOtherImage::VoxelType
219  GetWithPadding(const TOtherImage *, double, double, double = 0, double = 0) const;
220 
221  /// Evaluate generic image without handling boundary conditions
222  ///
223  /// This version is faster than EvaluateOutside, but is only defined inside
224  /// the domain for which all image values required for interpolation are
225  /// defined and thus require no extrapolation of the finite image.
226  virtual VoxelType GetInside(double, double, double = 0, double = 0) const;
227 
228  /// Evaluate generic image at an arbitrary location (in pixels)
229  virtual VoxelType GetOutside(double, double, double = 0, double = 0) const;
230 
231  /// Evaluate generic image without handling boundary conditions
232  ///
233  /// If the location is partially inside the foreground region of the image,
234  /// only the foreground values are interpolated. Otherwise, the _DefaultValue
235  /// is returned.
236  ///
237  /// This version is faster than GetWithPaddingOutside, but is only defined
238  /// inside the domain for which all image values required for interpolation
239  /// are defined and thus require no extrapolation of the finite image.
240  virtual VoxelType GetWithPaddingInside(double, double, double = 0, double = 0) const;
241 
242  /// Evaluate generic image at an arbitrary location (in pixels)
243  ///
244  /// If the location is partially inside the foreground region of the image,
245  /// only the foreground values are interpolated. Otherwise, the _DefaultValue
246  /// is returned.
247  virtual VoxelType GetWithPaddingOutside(double, double, double = 0, double = 0) const;
248 
249 };
250 
251 
252 /**
253  * Sinc interpolation of any scalar image
254  */
256 : public GenericSincInterpolateImageFunction<BaseImage>
257 {
258  mirtkObjectMacro(SincInterpolateImageFunction);
259 
260 public:
261 
262  /// Constructor
264 
265 };
266 
267 
268 } // namespace mirtk
269 
270 #endif // MIRTK_SincInterpolateImageFunction_H
VoxelType GetWithPadding2D(double, double, double=0, double=0) const
VoxelType Get4D(double, double, double=0, double=0) const
VoxelType GetWithPadding4D(double, double, double=0, double=0) const
virtual VoxelType GetWithPaddingInside(double, double, double=0, double=0) const
Definition: IOConfig.h:41
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)
Sinc< Real > Kernel
Sinc interpolation kernel function.
virtual VoxelType GetInside(double, double, double=0, double=0) const
mirtkPublicAttributeMacro(double, Epsilon)
Epsilon range within which to use nearest neighbor interpolation instead.
virtual VoxelType GetWithPadding(double, double, double=0, double=0) const
VoxelType Get(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 GetWithPadding3D(double, double, double=0, double=0) const
VoxelType Get3D(double, double, double=0, double=0) const