Skip to content

Commit

Permalink
Add use_hw_coords flag.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 584888162
  • Loading branch information
The visu3d Authors committed Nov 23, 2023
1 parent c3655de commit 1684a43
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Changelog follow https://keepachangelog.com/ format.

## [Unreleased]

## [1.5.4] - 2023-11-23

* Add `use_hw_coords` flag to `interp_img`.

## [1.5.3] - 2023-06-29

* Fix `etils` import error.
Expand Down
11 changes: 9 additions & 2 deletions visu3d/math/interp_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def interp_img(
img: Array['h w c'],
coords: FloatArray['*shape 2'],
*,
use_hw_coords: bool = False,
xnp: enp.NpModule = ...,
) -> FloatArray['*shape c']:
"""Bilinear interpolation of coordinates from an image.
Expand All @@ -33,19 +34,25 @@ def interp_img(
match `img[0, 0]`).
* Pixel coordinates are given in `coords=[w, h]`, NOT `[h, w]`. This is
consistent with `cam.spec.px_centers()` and OpenCv conventions.
To invert, use `coords[..., ::-1]`
To invert, set `use_hw_coords` to True.
* Coordinates outside the images use the image corners value.
Args:
img: Image from which interpolating values
coords: Pixel coordinates from which interpolate (in `w, h` convention).
coords: Pixel coordinates from which interpolate (in `w, h` convention,
unless `use_hw_coords` is True, in which case it will use the `h, w`
convention).
use_hw_coords: If True, coords will use (`h, w` convention).
xnp: Numpy module to use
Returns:
The interpolated pixel values at the requested coordinates.
Note that returned value is always float (so interpolation of `uint8`
return float)
"""
if use_hw_coords:
coords = coords[..., ::-1]

h, w, c = img.shape
*coord_shape, _ = coords.shape

Expand Down

0 comments on commit 1684a43

Please sign in to comment.