Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

fix overblur in AA (#1612)

Dmytro Mishkin3e638aef5736
diff --git a/kornia/geometry/transform/affwarp.py b/kornia/geometry/transform/affwarp.py
index 8fcad47d8..52b034158 100644
--- a/kornia/geometry/transform/affwarp.py
+++ b/kornia/geometry/transform/affwarp.py
@@ -581,12 +581,14 @@ def resize(
if antialias:
# First, we have to determine sigma
- sigmas = (max(factors[0], 1.0), max(factors[1], 1.0))
+ # Taken from skimage: https://github.com/scikit-image/scikit-image/blob/v0.19.2/skimage/transform/_warps.py#L171
+ sigmas = (max((factors[0] - 1.0) / 2.0, 0.001),
+ max((factors[1] - 1.0) / 2.0, 0.001))
# Now kernel size. Good results are for 3 sigma, but that is kind of slow. Pillow uses 1 sigma
# https://github.com/python-pillow/Pillow/blob/master/src/libImaging/Resample.c#L206
# But they do it in the 2 passes, which gives better results. Let's try 2 sigmas for now
- ks = int(2.0 * 2 * sigmas[0]), int(2.0 * 2 * sigmas[1])
+ ks = int(max(2.0 * 2 * sigmas[0], 3)), int(max(2.0 * 2 * sigmas[1], 3))
# Make sure it is odd
if (ks[0] % 2) == 0:
diff --git a/test/geometry/transform/test_affine.py b/test/geometry/transform/test_affine.py
index ceb0625f9..9c5b0e0e0 100644
--- a/test/geometry/transform/test_affine.py
+++ b/test/geometry/transform/test_affine.py
@@ -229,11 +229,11 @@ class TestRescale:
[
[
[
- [0.0255, 0.0453, 0.0759, 0.1065, 0.1263],
- [0.0453, 0.0804, 0.1347, 0.1890, 0.2240],
- [0.0759, 0.1347, 0.2256, 0.3166, 0.3753],
- [0.1065, 0.1890, 0.3166, 0.4442, 0.5266],
- [0.1263, 0.2240, 0.3753, 0.5266, 0.6244],
+ [0.0074, 0.0237, 0.0409, 0.0581, 0.0743],
+ [0.0237, 0.0756, 0.1306, 0.1856, 0.2376],
+ [0.0409, 0.1306, 0.2256, 0.3206, 0.4104],
+ [0.0581, 0.1856, 0.3206, 0.4556, 0.5832],
+ [0.0743, 0.2376, 0.4104, 0.5832, 0.7464]
]
]
],