Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

fixed affine 2d shearing matrix translations (#612)

shijianjian0f3e22a2626a
diff --git a/kornia/geometry/transform/imgwarp.py b/kornia/geometry/transform/imgwarp.py
index c27b5e8e1..c04f06666 100644
--- a/kornia/geometry/transform/imgwarp.py
+++ b/kornia/geometry/transform/imgwarp.py
@@ -474,8 +474,8 @@ def get_affine_matrix2d(translations: torch.Tensor, center: torch.Tensor, scale:
sy_tan = torch.tan(sy) # type: ignore
zeros = torch.zeros_like(sx) # type: ignore
ones = torch.ones_like(sx) # type: ignore
- shear_mat = torch.stack([ones, -sx_tan, sx_tan * x, # type: ignore # noqa: E241
- -sy_tan, ones + sx_tan * sy_tan, sy_tan * (-sx_tan * x + y)], # noqa: E241
+ shear_mat = torch.stack([ones, -sx_tan, sx_tan * y, # type: ignore # noqa: E241
+ -sy_tan, ones + sx_tan * sy_tan, sy_tan * (sx_tan * y + x)], # noqa: E241
dim=-1).view(-1, 2, 3)
shear_mat = convert_affinematrix_to_homography(shear_mat)
transform_h = transform_h @ shear_mat
diff --git a/test/geometry/transform/test_affine.py b/test/geometry/transform/test_affine.py
index 61a51b33d..c4205fe61 100644
--- a/test/geometry/transform/test_affine.py
+++ b/test/geometry/transform/test_affine.py
@@ -452,8 +452,8 @@ class TestAffine2d:
batch_size, ch, height, width = 1, 1, 96, 96
angle, translations = 6.971339922894188, (0.0, -4.0)
scale, shear = 0.7785685905190581, [11.8235607082617, 7.06797949691645]
- matrix_expected = T([[1.27536969, 4.26828945e-01, -3.23493180e+01],
- [2.18297196e-03, 1.29424165e+00, -9.19962753e+00]])
+ matrix_expected = T([[1.27536969, 4.26828945e-01, -3.2876e+01],
+ [2.18297196e-03, 1.29424165e+00, -1.1717e+01]])
center = T([float(width), float(height)]).view(1, 2) / 2. + 0.5
center = center.expand(batch_size, -1)
matrix_kornia = kornia.get_affine_matrix2d(