Skip to content

Instantly share code, notes, and snippets.

@ThomasParistech
Last active September 1, 2022 16:26
Show Gist options
  • Select an option

  • Save ThomasParistech/fec945b0a53eedad355fbda3f4e8804d to your computer and use it in GitHub Desktop.

Select an option

Save ThomasParistech/fec945b0a53eedad355fbda3f4e8804d to your computer and use it in GitHub Desktop.
import numpy as np
def get_up_mask(height: int, width: int) -> np.ndarray:
"""
Get the mask corresponding to the projection of the UP cubeface
on the equirectangular image
"""
mask = np.zeros((height, width // 4), bool)
# Get the mask above a single cubeface
theta = sample_pixels(-np.pi/4, np.pi/4, width // 4)
phi = -np.arctan(np.cos(theta))
phi_idx = ((phi/np.pi + 0.5) * height).astype(int)
for i, j in enumerate(phi_idx):
mask[:j, i] = True
# Repeat 4 times and roll by a half-cubeface
up_mask = np.tile(mask, 4)
return np.roll(up_mask, width // 8, axis=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment