Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

docs(color,geometry): state the integer-input contract instead of tracking #5109 and #3959 (#5990)

Dmytro Mishkin900cf024ba0f
diff --git a/kornia/color/gray.py b/kornia/color/gray.py
index 587be6a18..a5afb64df 100644
--- a/kornia/color/gray.py
+++ b/kornia/color/gray.py
@@ -69,8 +69,9 @@ def rgb_to_grayscale(image: torch.Tensor, rgb_weights: Optional[torch.Tensor] =
ITU-R BT.601 luma weights (0.299, 0.587, 0.114) in RGB order.
.. warning::
- On integer input, explicit float ``rgb_weights`` truncate to zero and integer weights wrap
- (`#5109 <https://github.com/kornia/kornia/issues/5109>`_).
+ Explicit ``rgb_weights`` expect a floating image: they are cast to the image's dtype, so on an integer image
+ float weights truncate to zero and integer weights wrap. With the default weights a uint8 image is converted
+ exactly, bit for bit as ``cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)`` does.
Args:
image: RGB image to be converted to grayscale with shape :math:`(*,3,H,W)`.
diff --git a/kornia/geometry/conversions.py b/kornia/geometry/conversions.py
index 58166efcc..92072a4cb 100644
--- a/kornia/geometry/conversions.py
+++ b/kornia/geometry/conversions.py
@@ -1832,10 +1832,9 @@ def normalize_homography(
kernel for it raises here
.. warning::
- An integer matrix is not rejected: the normalization matrices are cast
- to it and truncated, and the call then fails inside torch or returns
- ``nan``, depending on the backend. Tracked in
- `#3959 <https://github.com/kornia/kornia/issues/3959>`_.
+ An integer matrix is outside the contract and is not rejected: the
+ normalization matrices are cast to it and truncated, and the call then
+ fails inside torch or returns ``nan``, depending on the backend.
.. warning::
The :math:`[-1, 1]` frames follow this function's own ``align_corners``,
@@ -2252,8 +2251,7 @@ def denormalize_homography(
source pixels to destination pixels. The ``dsize`` roles, the
``(x, y, 1)`` column vectors, per-sample batching, the
``align_corners``-selected frames and the shape guard are as
- documented there, including its integer-input
- (`#3959 <https://github.com/kornia/kornia/issues/3959>`_) warning
+ documented there, including its integer-input warning
- ``inv(N_dst)`` goes through ``torch.linalg.inv`` in eager mode (so
``cusolver`` on ``cuda``), not through the ``cross``-based adjugate
- the two functions invert each other to a small multiple of the
@@ -2409,7 +2407,7 @@ def denormalize_homography3d(
``dst_pix_trans_src_pix`` raises ``TypeCheckError`` (also a
``TypeError``) instead of being promoted, so cast it first. Integers
would truncate the normalization matrices (the 2-D function still
- does, `#3959 <https://github.com/kornia/kornia/issues/3959>`_), and
+ does), and
complex dtypes would be inverted in ``float32``
(``_torch_inverse_cast``), losing ``complex128`` precision
@@ -2584,10 +2582,9 @@ def Rt_to_matrix4x4(R: torch.Tensor, t: torch.Tensor) -> torch.Tensor:
Note:
``R`` and ``t`` must promote to a floating point or complex dtype;
an integer or boolean pair raises ``ValueError`` naming its dtype.
- Mixed integer/floating inputs keep torch's promotion. The integer-safe
- ``_4x4`` frame functions and ``camtoworld_to_worldtocam_Rt`` keep their
- existing behavior; the broader dtype consistency question is tracked in
- `#3959 <https://github.com/kornia/kornia/issues/3959>`_.
+ Mixed integer/floating inputs keep torch's promotion. The ``_4x4``
+ frame functions and ``camtoworld_to_worldtocam_Rt`` only transpose,
+ negate and multiply, so they accept integer input as well.
Args:
R: Rotation matrix, :math:`(B, 3, 3).`
@@ -2699,8 +2696,7 @@ def camtoworld_graphics_to_vision_4x4(extrinsics_graphics: torch.Tensor) -> torc
Integer input is not guarded: this function returns ``int64`` for an
``int64`` matrix (on backends with integer batched matmul), while
:func:`~kornia.geometry.conversions.camtoworld_graphics_to_vision_Rt`
- raises ``ValueError`` naming the unsupported dtype. Tracked in
- `#3959 <https://github.com/kornia/kornia/issues/3959>`_; see
+ raises ``ValueError`` naming the unsupported dtype; see
:func:`~kornia.geometry.conversions.Rt_to_matrix4x4`.
Args: