mt.geo2d.linear
Module supporting the 2x2 linear transformation.
Functions
mat2sshr()
: Converts a 2d transformation matrix into an sshr tuple.mat2sshr_tf()
: Converts an array of 2x2 transformation matrices into an array of sshr tuples.sshr2mat()
: Converts an sshr tuple into a mat2 transformation matrices.sshr2mat_tf()
: Converts an array of sshr tuples into an array of 2x2 transformation matrices.make_affine()
: Makes an array of 2d affine transformation matrices (in 3x3 with [0,0,1] as the 3rd row).
- mt.geo2d.linear.mat2sshr(m: mat2x2) vec4
Converts a 2d transformation matrix into an sshr tuple.
An sshr tuple (sx,sy,h,r) represents the scale2d(sx,sy) shear2d(h) rotate2d(r) transformation.
Formula:
[[a0, a1], [a2, a3]] = m # row-major sy = hypot(a2,a3) r = atan2(a2,a3) sx = det(A)/sy h = (a0*a2 + a1*a3)/(sx*r)
- Parameters:
m (glm.mat2) – the input 2d transformation matrix
- Returns:
sshr – the output sshr tuple
- Return type:
glm.vec4
References
- mt.geo2d.linear.mat2sshr_tf(tensor)
Converts an array of 2x2 transformation matrices into an array of sshr tuples.
An sshr tuple (sx,sy,h,r) represents the scale2d(sx,sy) shear2d(h) rotate2d(r) transformation.
Formula:
[[a0, a1], [a2, a3]] = m sy = hypot(a2,a3) r = atan2(a2,a3) sx = det(A)/sy h = (a0*a2 + a1*a3)/(sx*r)
- Parameters:
tensor (tensorflow.Tensor) – a tensor of shape (batch, 2, 2) containing 2d row-major transformation matrices
- Returns:
a tensor of shape (batch, 4) containing sshr tuples
- Return type:
tensorflow.Tensor
References
[1] Pham et al, Distances and Means of Direct Similarities, IJCV, 2015. (not really, cheeky MT is trying to advertise his paper!)
- mt.geo2d.linear.sshr2mat(sshr: vec4) mat2x2
Converts an sshr tuple into a mat2 transformation matrices.
An sshr tuple (sx,sy,h,r) represents the scale2d(sx,sy) shear2d(h) rotate2d(r) transformation.
Formula:
cr = cos(r) sr = sin(r) a0 = sx*(h*sr + cr) a1 = sx*(h*cr - sr) a2 = sy*sr a3 = sy*cr m = [[a0, a1], [a2, a3]] # row-major
- Parameters:
sshr (glm.vec4) – the input sshr tuple
- Returns:
the output 2d transformation matrix
- Return type:
glm.mat2
References
[1] Pham et al, Distances and Means of Direct Similarities, IJCV, 2015. (not really, cheeky MT is trying to advertise his paper!)
- mt.geo2d.linear.sshr2mat_tf(tensor)
Converts an array of sshr tuples into an array of 2x2 transformation matrices.
An sshr tuple (sx,sy,h,r) represents the scale2d(sx,sy) shear2d(h) rotate2d(r) transformation.
Formula:
cr = cos(r) sr = sin(r) a0 = sx*(h*sr + cr) a1 = sx*(h*cr - sr) a2 = sy*sr a3 = sy*cr m = [[a0, a1], [a2, a3]]
- Parameters:
tensor (tensorflow.Tensor) – a tensor of shape (batch, 4) containing sshr tuples
- Returns:
a tensor of shape (batch, 2, 2) containing 2d row-major transformation matrices
- Return type:
tensorflow.Tensor
References
[1] Pham et al, Distances and Means of Direct Similarities, IJCV, 2015. (not really, cheeky MT is trying to advertise his paper!)
- mt.geo2d.linear.make_affine(mat2d_tensor, ofs2d_tensor)
Makes an array of 2d affine transformation matrices (in 3x3 with [0,0,1] as the 3rd row).
- Parameters:
mat2d_tensor (tensorflow.Tensor) – a tensor of shape (batch, 2, 2) containing 2d row-major transformation matrices
ofs2d_tensor (tensorflow.Tensor) – a tensor of shape (batch, 2) containing 2d translations
- Returns:
a tensor of shape (batch, 3, 3) containing 2d affine transformation matrices with the linear and translation parts defined in the input tensors
- Return type:
tensorflow.Tensor