Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

fix(geometry): rename ImageRegistrator.warp_dst_inro_src to warp_dst_into_src (#5049)

niukanen127364883a0a2
diff --git a/changelog.d/5049.added.md b/changelog.d/5049.added.md
new file mode 100644
index 000000000..2ea0306b7
--- /dev/null
+++ b/changelog.d/5049.added.md
@@ -0,0 +1 @@
+`ImageRegistrator.warp_dst_into_src`, the correctly spelled inverse of `warp_src_into_dst`; its docstring now names the argument it warps, `dst_img`. The misspelled `warp_dst_inro_src` still works as a deprecated alias that emits a `DeprecationWarning`.
diff --git a/kornia/geometry/transform/image_registrator.py b/kornia/geometry/transform/image_registrator.py
index e62d246a2..3ad055595 100644
--- a/kornia/geometry/transform/image_registrator.py
+++ b/kornia/geometry/transform/image_registrator.py
@@ -22,6 +22,7 @@ import torch
import torch.nn.functional as F
from torch import nn, optim
+from kornia.core._compat import deprecated
from kornia.core.utils import _torch_inverse_cast
from kornia.geometry.conversions import angle_to_rotation_matrix, convert_affinematrix_to_homography
@@ -316,8 +317,13 @@ class ImageRegistrator(nn.Module):
warper = self.warper(_height, _width)
return warper(src_img, self.model())
- def warp_dst_inro_src(self, dst_img: torch.Tensor) -> torch.Tensor:
- r"""Warp src_img with inverted estimated model."""
+ def warp_dst_into_src(self, dst_img: torch.Tensor) -> torch.Tensor:
+ r"""Warp dst_img with inverted estimated model."""
_height, _width = dst_img.shape[-2:]
warper = self.warper(_height, _width)
return warper(dst_img, self.model.forward_inverse())
+
+ @deprecated(replace_with="ImageRegistrator.warp_dst_into_src", version="0.9.0")
+ def warp_dst_inro_src(self, dst_img: torch.Tensor) -> torch.Tensor:
+ r"""Deprecated alias for :meth:`warp_dst_into_src`."""
+ return self.warp_dst_into_src(dst_img)
diff --git a/tests/geometry/transform/test_image_registrator.py b/tests/geometry/transform/test_image_registrator.py
index b4a226e3f..2196c8cb7 100644
--- a/tests/geometry/transform/test_image_registrator.py
+++ b/tests/geometry/transform/test_image_registrator.py
@@ -16,6 +16,7 @@
#
import sys
+import warnings
import pytest
import torch
@@ -143,3 +144,25 @@ class TestImageRegistrator(BaseTester):
with pytest.raises(ValueError):
registrator.register(img1, img2)
+
+ def test_warp_dst_into_src_and_deprecated_alias(self, device, dtype):
+ ch, height, width = 1, 8, 10
+ ir = ImageRegistrator("Similarity").to(device, dtype)
+ # A pure shift, so that the inverse warp differs from the forward one and equals the forward warp of the
+ # opposite shift. An identity model cannot tell the two directions apart.
+ with torch.no_grad():
+ ir.model.shift.copy_(torch.tensor([[[0.5], [-0.25]]], device=device, dtype=dtype))
+ opposite = ImageRegistrator("Similarity").to(device, dtype)
+ with torch.no_grad():
+ opposite.model.shift.copy_(-ir.model.shift)
+ dst = torch.rand(1, ch, height, width, device=device, dtype=dtype)
+
+ with warnings.catch_warnings():
+ warnings.simplefilter("error")
+ into_src = ir.warp_dst_into_src(dst)
+ self.assert_close(into_src, opposite.warp_src_into_dst(dst))
+ assert not torch.allclose(into_src, ir.warp_src_into_dst(dst))
+
+ with pytest.warns(DeprecationWarning, match="`warp_dst_inro_src` is deprecated in favor of"):
+ via_alias = ir.warp_dst_inro_src(dst)
+ self.assert_close(via_alias, into_src)