1
1
""" Transformations produced by registration methods """
2
2
import numpy as np
3
- from thunder .imgprocessing .regmethods .utils import zeroBorder , imageGradients , v2v
4
- from thunder .utils .decorators import serializable
3
+
5
4
6
5
class Transformation (object ):
7
6
""" Base class for transformations """
@@ -12,7 +11,7 @@ def apply(self, im):
12
11
13
12
class DifferentiableTransformation (Transformation ):
14
13
"""
15
- Differentiable transformations must have methods to ompute the Jacobian and update parameters. These are used by
14
+ Differentiable transformations must have methods to compute the Jacobian and update parameters. These are used by
16
15
iterative alignment techniques like Lucas-Kanade and RASL.
17
16
"""
18
17
def jacobian (self , imageGradients , imageGrid ):
@@ -77,13 +76,24 @@ def updateParams(self, deltaParams):
77
76
self .delta += deltaParams
78
77
79
78
class EuclideanTransformation (AffineTransformation ):
80
- def __init__ (self , shift , rotation = None , zTranslation = False , zRotation = False ):
79
+ def __init__ (self , shift , rotation = None , zTranslation = False , zRotation = False , center = None ):
81
80
"""Translation and rotation in 3d.
82
81
83
82
Parameters
84
83
----------
85
- shift :
86
- rot :
84
+ shift : list or array
85
+ spatial shifts for each dimension
86
+ rotation : float, list, or array
87
+ rotation in x-y if scalar. rotation in x-y plane, x-z plane, y-z plane if list
88
+ or array and dataset is in 3d.
89
+ zTranslation : bool, optional, default = False
90
+ whether to allow translation in z
91
+ zRotation : bool, optional, default = False
92
+ whether to allow rotation in z
93
+ center : list or array, optional, default = None
94
+ Set center coordinates that define the point around which the volume is rotated.
95
+ Coordinates should be in terms of zero-indexed pixels. For example if the volume was 5x5x3,
96
+ the default center of rotation would be at the center of the volume: (2, 2, 1).
87
97
"""
88
98
self .shift = np .atleast_1d (shift )
89
99
self .ndim = len (self .shift )
@@ -95,6 +105,7 @@ def __init__(self, shift, rotation=None, zTranslation=False, zRotation=False):
95
105
self .rotation = np .atleast_1d (rotation )
96
106
self .zRotation = zRotation
97
107
self .zTranslation = zTranslation
108
+ self .center = center
98
109
99
110
def updateParams (self , deltaParams ):
100
111
if self .ndim == 2 :
@@ -148,7 +159,7 @@ def jacobian(self, imageGradients, imageGrid):
148
159
dpsi += imageGradients [2 ] * (imageGrid [1 ] * cphi * cpsi - imageGrid [2 ] * cphi * spsi )
149
160
dangles = [dtheta , dphi , dpsi ]
150
161
151
- # Zero-out Jacobian corresponding to z transltation
162
+ # Zero-out Jacobian corresponding to z translation
152
163
if ndim == 3 and not self .zTranslation :
153
164
imageGradients [2 ][:] = 0.0
154
165
return imageGradients + dangles
@@ -159,6 +170,7 @@ def matrix(self):
159
170
def __repr__ (self ):
160
171
return "EuclideanTransformation(shift=%s, rotation=%s)" % (repr (self .shift ), repr (self .rotation ))
161
172
173
+
162
174
class Displacement (Transformation ):
163
175
"""
164
176
Class for transformations based on spatial displacements.
@@ -168,7 +180,7 @@ class Displacement(Transformation):
168
180
Parameters
169
181
----------
170
182
delta : list
171
- A list of spatial displacements for each dimensino ,
183
+ A list of spatial displacements for each dimension ,
172
184
e.g. [10,5,2] for a displacement of 10 in x, 5 in y, 2 in z
173
185
"""
174
186
@@ -256,7 +268,7 @@ def __init__(self, dims, center=None):
256
268
257
269
def transform_grid_world (self , A ):
258
270
"""Get the grid of points in world space after applying the given affine transform."""
259
- return np .tensordot (A .T , self .homo_points , axes = (0 ,0 ))
271
+ return np .tensordot (A .T , self .homo_points , axes = (0 , 0 ))
260
272
261
273
def transform_grid (self , A ):
262
274
"""Get the grid of points in index space after applying the given affine transform
@@ -288,7 +300,7 @@ def transformationMatrix(shift, rot=None):
288
300
Returns
289
301
-------
290
302
A : array, shape (ndims + 1, ndims + 1)
291
- transformation matrix that shifts and rotates a set of points in homogenous coordinates
303
+ transformation matrix that shifts and rotates a set of points in homogeneous coordinates
292
304
"""
293
305
294
306
ndim = len (shift )
@@ -319,7 +331,8 @@ def transformationMatrix(shift, rot=None):
319
331
A = np .dot (trans , np .dot (xrot , np .dot (yrot , zrot )))
320
332
return A
321
333
334
+ # Dict of valid types of Transformations used by Lucas-Kanade
322
335
TRANSFORMATION_TYPES = {
323
- 'Translation' : TranslationTransformation ,
324
- 'Euclidean' : EuclideanTransformation
336
+ 'Translation' : TranslationTransformation ,
337
+ 'Euclidean' : EuclideanTransformation
325
338
}
0 commit comments