11""" Transformations produced by registration methods """
22import numpy as np
3- from thunder .imgprocessing .regmethods .utils import zeroBorder , imageGradients , v2v
4- from thunder .utils .decorators import serializable
3+
54
65class Transformation (object ):
76 """ Base class for transformations """
@@ -12,7 +11,7 @@ def apply(self, im):
1211
1312class DifferentiableTransformation (Transformation ):
1413 """
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
1615 iterative alignment techniques like Lucas-Kanade and RASL.
1716 """
1817 def jacobian (self , imageGradients , imageGrid ):
@@ -77,13 +76,24 @@ def updateParams(self, deltaParams):
7776 self .delta += deltaParams
7877
7978class 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 ):
8180 """Translation and rotation in 3d.
8281
8382 Parameters
8483 ----------
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).
8797 """
8898 self .shift = np .atleast_1d (shift )
8999 self .ndim = len (self .shift )
@@ -95,6 +105,7 @@ def __init__(self, shift, rotation=None, zTranslation=False, zRotation=False):
95105 self .rotation = np .atleast_1d (rotation )
96106 self .zRotation = zRotation
97107 self .zTranslation = zTranslation
108+ self .center = center
98109
99110 def updateParams (self , deltaParams ):
100111 if self .ndim == 2 :
@@ -148,7 +159,7 @@ def jacobian(self, imageGradients, imageGrid):
148159 dpsi += imageGradients [2 ] * (imageGrid [1 ] * cphi * cpsi - imageGrid [2 ] * cphi * spsi )
149160 dangles = [dtheta , dphi , dpsi ]
150161
151- # Zero-out Jacobian corresponding to z transltation
162+ # Zero-out Jacobian corresponding to z translation
152163 if ndim == 3 and not self .zTranslation :
153164 imageGradients [2 ][:] = 0.0
154165 return imageGradients + dangles
@@ -159,6 +170,7 @@ def matrix(self):
159170 def __repr__ (self ):
160171 return "EuclideanTransformation(shift=%s, rotation=%s)" % (repr (self .shift ), repr (self .rotation ))
161172
173+
162174class Displacement (Transformation ):
163175 """
164176 Class for transformations based on spatial displacements.
@@ -168,7 +180,7 @@ class Displacement(Transformation):
168180 Parameters
169181 ----------
170182 delta : list
171- A list of spatial displacements for each dimensino ,
183+ A list of spatial displacements for each dimension ,
172184 e.g. [10,5,2] for a displacement of 10 in x, 5 in y, 2 in z
173185 """
174186
@@ -256,7 +268,7 @@ def __init__(self, dims, center=None):
256268
257269 def transform_grid_world (self , A ):
258270 """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 ))
260272
261273 def transform_grid (self , A ):
262274 """Get the grid of points in index space after applying the given affine transform
@@ -288,7 +300,7 @@ def transformationMatrix(shift, rot=None):
288300 Returns
289301 -------
290302 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
292304 """
293305
294306 ndim = len (shift )
@@ -319,7 +331,8 @@ def transformationMatrix(shift, rot=None):
319331 A = np .dot (trans , np .dot (xrot , np .dot (yrot , zrot )))
320332 return A
321333
334+ # Dict of valid types of Transformations used by Lucas-Kanade
322335TRANSFORMATION_TYPES = {
323- 'Translation' : TranslationTransformation ,
324- 'Euclidean' : EuclideanTransformation
336+ 'Translation' : TranslationTransformation ,
337+ 'Euclidean' : EuclideanTransformation
325338}
0 commit comments