Skip to content

Commit

Permalink
change padding ordering so we don't need to do wrap border-mode; fix …
Browse files Browse the repository at this point in the history
…off-by-one error for opencv.
  • Loading branch information
BrianPugh committed Dec 21, 2024
1 parent 28242bf commit 7019609
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions py360convert/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ def __init__(
coor_y: NDArray,
order: int,
):
# Add 1 to the coordinates to compensate for the 1 pixel upper padding.
coor_y = coor_y + 1 # Not done inplace on purpose.
if cv2 and order in (0, 1, 3):
self._use_cv2 = True
if order == 0:
Expand All @@ -345,7 +347,6 @@ def __init__(
else:
raise NotImplementedError

# TODO: I think coor_y has an off-by-one due to the 1 pixel padding?
self._coor_x, self._coor_y = cv2.convertMaps(
coor_x,
coor_y,
Expand All @@ -367,18 +368,17 @@ def __call__(self, img: NDArray[DType]) -> NDArray[DType]:
padded,
(self._coor_y, self._coor_x),
order=self._order,
mode="wrap",
)[..., 0]

return out # pyright: ignore[reportReturnType]

def _pad(self, img: NDArray[DType]) -> NDArray[DType]:
"""Adds 1 pixel of padding above/below image."""
w = img.shape[1]
pad_u = np.roll(img[[0]], w // 2, 1)
pad_d = np.roll(img[[-1]], w // 2, 1)
img = np.concatenate([img, pad_d, pad_u], 0, dtype=img.dtype)
return img
padded = np.pad(img, ((1, 1), (0, 0)), mode="empty")
padded[0, :] = np.roll(img[[0]], w // 2, 1)
padded[-1, :] = np.roll(img[[-1]], w // 2, 1)
return padded


class CubeFaceSampler:
Expand Down

0 comments on commit 7019609

Please sign in to comment.