ShapeBasedInterpolateImageFunction.h
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2010-2015 Imperial College London
5  * Copyright 2010 Wenzhe Shi
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_ShapeBasedInterpolateImageFunction_H
21 #define MIRTK_ShapeBasedInterpolateImageFunction_H
22 
23 #include "mirtk/InterpolateImageFunction.h"
24 
25 #include "mirtk/Math.h"
26 #include "mirtk/GenericImage.h"
27 #include "mirtk/LinearInterpolateImageFunction.h"
28 #include "mirtk/NearestNeighborInterpolateImageFunction.h"
29 
30 
31 namespace mirtk {
32 
33 
34 /**
35  * Shape based interpolation of 3D scalar images
36  *
37  * This class defines and implements a shape based interpolation of images.
38  */
40 {
41  mirtkInterpolatorMacro(
43  Interpolation_SBased
44  );
45 
46  // ---------------------------------------------------------------------------
47  // Attributes
48 
49 protected:
50 
51  /// Threshold map for input image
53 
54  /// Distance map for input image
56 
57  /// Isotropic resampled distance map for input image with linear interpolation
59 
60  /// Isotropic resampled Input image after shape based interpolation
62 
63  /// Isotropic resampled cache image for refine procedure
65 
66  /// Image function for nearest neighbor interpolation of resampled input
68 
69  /// Image function for linear interpolation of resampled input
71 
72  /// Initialize second step, fix the union property
73  void Refine();
74 
75 public:
76 
77  // ---------------------------------------------------------------------------
78  // Construction/Destruction
79 
80  /// Constructor
82 
83  /// Destructor
85 
86  /// Initialize
87  virtual void Initialize(bool = false);
88 
89  // ---------------------------------------------------------------------------
90  // Domain checks
91 
92  /// Returns interval of discrete image indices whose values are needed for
93  /// interpolation of the image value at a given continuous coordinate
94  virtual void BoundingInterval(double, int &, int &) const;
95 
96  // ---------------------------------------------------------------------------
97  // Evaluation
98 
99  // import non-overridden overloads
104 
105  /// Evaluate scalar image without handling boundary conditions
106  ///
107  /// This version is faster than EvaluateOutside, but is only defined inside
108  /// the domain for which all image values required for interpolation are
109  /// defined and thus require no extrapolation of the finite image.
110  virtual double EvaluateInside(double, double, double, double = 0) const;
111 
112  /// Evaluate scalar image at an arbitrary location (in pixels)
113  virtual double EvaluateOutside(double, double, double, double = 0) const;
114 
115  /// Evaluate scalar image at an arbitrary location (in pixels)
116  ///
117  /// If the location is partially inside the foreground region of the image,
118  /// only the foreground values are interpolated. Otherwise, the _DefaultValue
119  /// is returned.
120  ///
121  /// This version is faster than EvaluateWithPaddingOutside, but is only defined
122  /// inside the domain for which all image values required for interpolation are
123  /// defined and thus require no extrapolation of the finite image.
124  virtual double EvaluateWithPaddingInside(double, double, double, double = 0) const;
125 
126  /// Evaluate scalar image at an arbitrary location (in pixels)
127  ///
128  /// If the location is partially inside the foreground region of the image,
129  /// only the foreground values are interpolated. Otherwise, the _DefaultValue
130  /// is returned.
131  virtual double EvaluateWithPaddingOutside(double, double, double, double = 0) const;
132 
133  /// Evaluate vector image without handling boundary conditions
134  ///
135  /// This version is faster than EvaluateOutside, but is only defined inside
136  /// the domain for which all image values required for interpolation are
137  /// defined and thus require no extrapolation of the finite image.
138  ///
139  /// \attention This interpolator is implemented only for scalar images!
140  virtual void EvaluateInside(Vector &, double, double, double, double = 0) const;
141 
142  /// Evaluate vector image at an arbitrary location (in pixels)
143  ///
144  /// \attention This interpolator is implemented only for scalar images!
145  virtual void EvaluateOutside(Vector &, double, double, double, double = 0) const;
146 
147  /// Evaluate vector image at an arbitrary location (in pixels)
148  ///
149  /// If the location is partially inside the foreground region of the image,
150  /// only the foreground values are interpolated. Otherwise, a vector set to
151  /// the _DefaultValue is returned.
152  ///
153  /// This version is faster than EvaluateWithPaddingOutside, but is only defined
154  /// inside the domain for which all image values required for interpolation are
155  /// defined and thus require no extrapolation of the finite image.
156  ///
157  /// \attention This interpolator is implemented only for scalar images!
158  virtual void EvaluateWithPaddingInside(Vector &, double, double, double, double = 0) const;
159 
160  /// Evaluate vector image at an arbitrary location (in pixels)
161  ///
162  /// If the location is partially inside the foreground region of the image,
163  /// only the foreground values are interpolated. Otherwise, a vector set to
164  /// the _DefaultValue is returned.
165  ///
166  /// \attention This interpolator is implemented only for scalar images!
167  virtual void EvaluateWithPaddingOutside(Vector &, double, double, double, double = 0) const;
168 
169  /// Evaluate the filter at arbitrary image location (in pixels)
170  virtual double EvaluateLinear(double, double, double, double = 0) const;
171 
172  /// Evaluate the filter at an arbitrary image location (in pixels) without
173  /// handling boundary conditions. This version is faster than the method
174  /// above, but is only defined inside the image domain.
175  virtual double EvaluateInsideLinear(double, double, double, double = 0) const;
176 
177  /// Evaluate the filter at a boundary image location (in pixels)
178  virtual double EvaluateOutsideLinear(double, double, double, double = 0) const;
179 
180 };
181 
182 ////////////////////////////////////////////////////////////////////////////////
183 // Inline definitions
184 ////////////////////////////////////////////////////////////////////////////////
185 
186 // =============================================================================
187 // Domain checks
188 // =============================================================================
189 
190 // -----------------------------------------------------------------------------
192 ::BoundingInterval(double x, int &i, int &I) const
193 {
194  i = I = iround(x);
195 }
196 
197 // =============================================================================
198 // Evaluation
199 // =============================================================================
200 
201 // -----------------------------------------------------------------------------
203 ::EvaluateInside(Vector &v, double x, double y, double z, double t) const
204 {
205  v = this->EvaluateInside(x, y, z, t);
206 }
207 
208 // -----------------------------------------------------------------------------
210 ::EvaluateOutside(Vector &v, double x, double y, double z, double t) const
211 {
212  v = this->EvaluateOutside(x, y, z, t);
213 }
214 
215 // -----------------------------------------------------------------------------
217 ::EvaluateWithPaddingInside(Vector &v, double x, double y, double z, double t) const
218 {
219  v = this->EvaluateWithPaddingInside(x, y, z, t);
220 }
221 
222 // -----------------------------------------------------------------------------
224 ::EvaluateWithPaddingOutside(Vector &v, double x, double y, double z, double t) const
225 {
226  v = this->EvaluateWithPaddingOutside(x, y, z, t);
227 }
228 
229 
230 } // namespace mirtk
231 
232 #endif // MIRTK_ShapeBasedInterpolateImageFunction_H
virtual double EvaluateWithPaddingOutside(double, double, double, double=0) const
NearestNeighborInterpolateImageFunction _nn_interpolator
Image function for nearest neighbor interpolation of resampled input.
virtual void BoundingInterval(double, int &, int &) const
virtual double EvaluateInside(double, double, double=0, double=0) const =0
virtual double EvaluateInsideLinear(double, double, double, double=0) const
Definition: IOConfig.h:41
RealImage _rcdmap
Isotropic resampled cache image for refine procedure.
virtual double EvaluateInside(double, double, double, double=0) const
virtual ~ShapeBasedInterpolateImageFunction()
Destructor.
virtual double EvaluateOutsideLinear(double, double, double, double=0) const
Evaluate the filter at a boundary image location (in pixels)
RealImage _tinput
Threshold map for input image.
virtual double EvaluateWithPaddingInside(double, double, double=0, double=0) const =0
RealImage _rinput
Isotropic resampled Input image after shape based interpolation.
virtual double EvaluateWithPaddingOutside(double, double, double=0, double=0) const =0
LinearInterpolateImageFunction _linear_interpolator
Image function for linear interpolation of resampled input.
virtual double EvaluateOutside(double, double, double, double=0) const
Evaluate scalar image at an arbitrary location (in pixels)
RealImage _rdmap
Isotropic resampled distance map for input image with linear interpolation.
void Refine()
Initialize second step, fix the union property.
MIRTKCU_API int iround(T x)
Round floating-point value and cast to int.
Definition: Math.h:170
virtual double EvaluateWithPaddingInside(double, double, double, double=0) const
virtual double EvaluateOutside(double, double, double=0, double=0) const =0
Evaluate scalar image at an arbitrary location (in pixels)
virtual double EvaluateLinear(double, double, double, double=0) const
Evaluate the filter at arbitrary image location (in pixels)