Skip to content

Instantly share code, notes, and snippets.

@ThomasParistech
Last active September 2, 2022 07:36
Show Gist options
  • Select an option

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

Select an option

Save ThomasParistech/2c88b8a10c280e78bf000fdd085f333b to your computer and use it in GitHub Desktop.
from typing import List
import numpy as np
import cv2
def cubemap_to_equirec(cubefaces: List[np.ndarray]) -> np.ndarray:
"""Convert a list of cubefaces (FRBLUD) into an equirectangular image"""
# Stack cubefaces horizontally
cubemap = np.hstack(cubefaces)
# Set the width of the output image to a multiple of 8
face_size = cubemap.shape[0]
out_height = (int(face_size * np.pi) // 8) * 4
out_width = out_height * 2
# XY maps
frbl_x, frbl_y = get_frbl_maps(out_width, out_height, face_size)
ud_x, ud_y = get_ud_maps(out_width, out_height, face_size)
# Combine
ceiling = get_up_mask(out_height, out_width).astype(np.float32)
ceiling += np.flipud(ceiling)
map_x = ceiling*ud_x + (1-ceiling)*frbl_x
map_y = ceiling*ud_y + (1-ceiling)*frbl_y
# Opencv shift
map_x -= 0.5
map_y -= 0.5
return cv2.remap(cubemap, map_x, map_y, cv2.INTER_CUBIC,
borderMode=cv2.BORDER_REPLICATE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment