Seg3D  2.4
Seg3D is a free volume segmentation and processing tool developed by the NIH Center for Integrative Biomedical Computing at the University of Utah Scientific Computing and Imaging (SCI) Institute.
itkRBFTransform.h
1 /*
2  For more information, please see: http://software.sci.utah.edu
3 
4  The MIT License
5 
6  Copyright (c) 2016 Scientific Computing and Imaging Institute,
7  University of Utah.
8 
9 
10  Permission is hereby granted, free of charge, to any person obtaining a
11  copy of this software and associated documentation files (the "Software"),
12  to deal in the Software without restriction, including without limitation
13  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included
18  in all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  DEALINGS IN THE SOFTWARE.
27 */
28 
29 // File : itkRBFTransform.h
30 // Author : Pavel A. Koshevoy
31 // Created : 2007/01/23 10:15
32 // Copyright : (C) 2004-2008 University of Utah
33 // Description : A Thin Plate Spline transform.
34 
35 #ifndef __itkRBFTransform_h
36 #define __itkRBFTransform_h
37 
38 // system includes:
39 #include <iostream>
40 #include <assert.h>
41 
42 // ITK includes:
43 #include <itkTransform.h>
44 #include <itkExceptionObject.h>
45 #include <itkMacro.h>
46 
47 // local includes:
48 #include <Core/ITKCommon/Transform/itkInverseTransform.h>
49 
50 
51 //----------------------------------------------------------------
52 // itk::RBFTransform
53 //
54 // Radial Basis Function transform:
55 //
56 // Let
57 // A = (u - uc) / Xmax
58 // B = (v - vc) / Ymax
59 // Ci = (u - ui) / Xmax
60 // Di = (v - vi) / Ymax
61 //
62 // where Xmax, Ymax are normalization parameters (typically the width and
63 // height of the image), uc, vc corresponds to the center or rotation
64 // of the image expressed in the coordinate system of the mosaic,
65 // and ui, vi are the mosaic space coordinates of the control points.
66 //
67 // The transform is defined as
68 // x(u, v) = Xmax * (a0 + a1 * A + a2 * B + F)
69 // y(u, v) = Ymax * (b0 + b1 * A + b2 * B + G)
70 //
71 // where
72 // F = sum(i in [0, k-1], fi * Q(Ci, Di));
73 // G = sum(i in [0, k-1], gi * Q(Ci, Di));
74 // Q = r2 * ln(r2)
75 // r2 = Ci^2 + Di^2
76 //
77 namespace itk
78 {
79 
80 class RBFTransform : public Transform<double, 2, 2>
81 {
82 public:
83  // standard typedefs:
84  typedef RBFTransform Self;
85  typedef Transform<double, 2, 2> Superclass;
86  typedef SmartPointer<Self> Pointer;
87  typedef SmartPointer<const Self> ConstPointer;
88 
91  typedef Superclass::InverseTransformBaseType InverseTransformBaseType;
92  typedef InverseTransformBaseType::Pointer InverseTransformBasePointer;
93 
94  // RTTI:
95  itkTypeMacro(RBFTransform, Transform);
96 
97  // macro for instantiation through the object factory:
98  itkNewMacro(Self);
99 
101  typedef double ScalarType;
102 
104  itkStaticConstMacro(InputSpaceDimension, unsigned int, 2);
105  itkStaticConstMacro(OutputSpaceDimension, unsigned int, 2);
106 
107  // shortcuts:
108  typedef Superclass::ParametersType ParametersType;
109  typedef Superclass::JacobianType JacobianType;
110 
111  typedef Superclass::InputPointType InputPointType;
112  typedef Superclass::OutputPointType OutputPointType;
113 
114  // virtual:
115  virtual OutputPointType TransformPoint(const InputPointType & uv) const;
116 
117  // Inverse transformations:
118  // If y = Transform(x), then x = BackTransform(y);
119  // if no mapping from y to x exists, then an exception is thrown.
120  InputPointType BackTransformPoint(const OutputPointType & y) const;
121 
122  // virtual:
123  virtual
124  void SetFixedParameters(const ParametersType & params)
125  { this->m_FixedParameters = params; }
126 
127  // virtual:
128  virtual
129  const ParametersType & GetFixedParameters() const
130  { return this->m_FixedParameters; }
131 
132  // virtual:
133  virtual
134  void SetParameters(const ParametersType & params)
135  { this->m_Parameters = params; }
136 
137  // virtual:
138  virtual
139  const ParametersType & GetParameters() const
140  { return this->m_Parameters; }
141 
142  // virtual:
143  virtual
144  NumberOfParametersType GetNumberOfParameters() const
145  { return this->m_Parameters.size(); }
146 
147  bool GetInverse(Self* inverse) const;
148 
149  // virtual: return an inverse of this transform.
150  virtual InverseTransformBasePointer GetInverseTransform() const;
151 
152  // setup the transform parameters:
153  void setup(// image bounding box expressed in the image space,
154  // defines transform normalization parameters:
155  const OutputPointType & tile_min, // tile space
156  const OutputPointType & tile_max, // tile space
157 
158  // landmark correspondences:
159  const unsigned int num_pts, // number of pairs
160  const InputPointType * uv, // mosaic space
161  const OutputPointType * xy); // tile space
162 
163  // virtual:
164 // virtual
165 // const JacobianType & GetJacobian(const InputPointType & point) const;
166 
167  virtual void ComputeJacobianWithRespectToParameters( const InputPointType &, JacobianType & ) const;
168 
169 #if 0
170 // // helper required for numeric inverse transform calculation;
171 // // evaluate F = T(x), J = dT/dx (another Jacobian):
172 // void eval(const std::vector<double> & x,
173 // std::vector<double> & F,
174 // std::vector<std::vector<double> > & J) const;
175 #endif
176 
177  // number of landmark correspondences:
178  inline unsigned int num_points() const
179  { return (this->m_FixedParameters.size() - 4) / 2; }
180 
181  // calculate parameter vector indeces for various transform parameters:
182  inline static unsigned int index_a(const unsigned int & i)
183  { return i * 2; }
184 
185  inline static unsigned int index_b(const unsigned int & i)
186  { return i * 2 + 1; }
187 
188  inline static unsigned int index_f(const unsigned int & i)
189  { return i * 2 + 6; }
190 
191  inline static unsigned int index_g(const unsigned int & i)
192  { return i * 2 + 7; }
193 
194  inline static unsigned int index_uv(const unsigned int & i)
195  { return i * 2 + 4; }
196 
197  // accessors to the normalization parameters Xmax, Ymax:
198  inline const double & GetXmax() const
199  { return this->m_FixedParameters[0]; }
200 
201  inline const double & GetYmax() const
202  { return this->m_FixedParameters[1]; }
203 
204  // accessors to the warp origin expressed in the mosaic coordinate system:
205  inline const double & GetUc() const
206  { return this->m_FixedParameters[2]; }
207 
208  inline const double & GetVc() const
209  { return this->m_FixedParameters[3]; }
210 
211  // mosaic space landmark accessor:
212  inline const double * uv(const unsigned int & i) const
213  { return &(this->m_FixedParameters[index_uv(i)]); }
214 
215  // polynomial coefficient accessors:
216  inline const double & a(const unsigned int & i) const
217  { return this->m_Parameters[index_a(i)]; }
218 
219  inline const double & b(const unsigned int & i) const
220  { return this->m_Parameters[index_b(i)]; }
221 
222  // radial basis function accessors:
223  inline const double & f(const unsigned int & i) const
224  { return this->m_Parameters[index_f(i)]; }
225 
226  inline const double & g(const unsigned int & i) const
227  { return this->m_Parameters[index_g(i)]; }
228 
229  // the Radial Basis Function kernel:
230  inline static double kernel(const double * uv,
231  const double * uv_i,
232  const double & Xmax,
233  const double & Ymax)
234  {
235  double U = (uv[0] - uv_i[0]) / Xmax;
236  double V = (uv[1] - uv_i[1]) / Ymax;
237  double R = U * U + V * V;
238  return R == 0 ? 0 : R * log(R);
239  }
240 
241 protected:
242  RBFTransform();
243  ~RBFTransform();
244 
245  // virtual:
246  virtual
247  void PrintSelf(std::ostream & s, Indent indent) const;
248 
249 private:
250  // disable default copy constructor and assignment operator:
251  RBFTransform(const Self & other);
252  const Self & operator = (const Self & t);
253 
254 }; // class RBFTransform
255 
256 } // namespace itk
257 
258 
259 #endif // __itkRBFTransform_h
itkStaticConstMacro(InputSpaceDimension, unsigned int, 2)
Superclass::InverseTransformBaseType InverseTransformBaseType
Definition: itkRBFTransform.h:91
Definition: itkRBFTransform.h:80
Definition: itkNormalizeImageFilterWithMask.h:48
double ScalarType
Definition: itkRBFTransform.h:101