Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change padding ordering so we don't need to do wrap border-mode; fix off-by-one error for opencv. #39

Merged
merged 1 commit into from
Dec 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading