Skip to main content

py360convert

Features of this project:

  • Conversion between cubemap and equirectangular:
  • Conversion between Equirectangular and planar:
  • Pure python implementation and depend only on numpy and scipy.
  • Vectorization implementation:
    • If opencv is installed, py360convert will automatically use it to accelerate computations (several times speedup).

Install

pip install py360convert

You can use the library with import py360convert and through the command line tool convert360.

Command line examples

The convert360 command line tool can be run like so. Use convert360 -h for details. The convert360 python script is also doubles as ab example code for how to use this as a package in your code.

convert360 e2c assets/example_input.png out.png --size 200
Input Equirectangular Output Cubemap

convert360 c2e assets/example_e2c.png out.png --width 800 --height 400
Input Cubemap Output Equirectangular

You can see the blurring artifacts in the polar region because the equirectangular in above figure are resampled twice (e2c then c2e).


convert360 e2p assets/example_input.png out.png --width 300 --height 300 --yaw 120 --pitch 23
Input Equirectangular Output Perspective

Doc

c2e(cubemap, h, w, cube_format='dice')

Convert the given cubemap to equirectangular.
Parameters:

  • cubemap: Numpy array or list/dict of numpy array (depend on cube_format).

  • h: Output equirectangular height.

  • w: Output equirectangular width.

  • mode:str: Interpolation method; typically bilinear or nearest. Valid options: "nearest", "linear", "bilinear", "biquadratic", "quadratic", "quad", "bicubic", "cubic", "biquartic", "quartic", "biquintic", "quintic".

  • cube_format: Options: 'dice' (default), 'horizon' or 'dict' or 'list'. Indicates the format of the given cubemap.

    • Say that each face of the cube is in shape of 256 (width) x 256 (height)

    • 'dice': a numpy array in shape of 1024 x 768 like below example

    • 'horizon': a numpy array in shape of 1536 x 256 like below example

    • 'list': a list with 6 elements each of which is a numpy array in the shape of 256 x 256. It's just converted from 'horizon' format with one line of code: np.split(cube_h, 6, axis=1).

    • 'dict': a dict with 6 elements with keys 'F', 'R', 'B', 'L', 'U', 'D' each of which is a numpy array in shape of 256 x 256.

    • Please refer to the source code if you still have any questions about the conversion between formats.

e2c(e_img, face_w=256, mode='bilinear', cube_format='dice')

Convert the given equirectangular to cubemap.
Parameters:

  • e_img: NDArray: Numpy array with shape [H, W, C].
  • face_w: int: The width of each cube face.
  • mode:str: See c2e.
  • cube_format:str: See c2e.

e2p(e_img, fov_deg, u_deg, v_deg, out_hw, in_rot_deg=0, mode='bilinear')

Take perspective image from given equirectangular. Parameters:

  • e_img: Numpy array with shape [H, W, C].
  • fov_deg: Field of view given in int or tuple (h_fov_deg, v_fov_deg).
  • u_deg: Horizontal viewing angle in range [-pi, pi]. (- Left / + Right).
  • v_deg: Vertical viewing angle in range [-pi/2, pi/2]. (- Down/ + Up).
  • out_hw: Output image (height, width) in tuple.
  • in_rot_deg: Inplane rotation.
  • mode: bilinear or nearest.

Example:

import numpy as np
from PIL import Image
import py360convert

cube_dice = np.array(Image.open('assets/demo_cube.png'))

# You can make conversion between supported cubemap format
cube_h = py360convert.cube_dice2h(cube_dice)  # the inverse is cube_h2dice
cube_dict = py360convert.cube_h2dict(cube_h)  # the inverse is cube_dict2h
cube_list = py360convert.cube_h2list(cube_h)  # the inverse is cube_list2h
print('cube_dice.shape:', cube_dice.shape)
print('cube_h.shape:', cube_h.shape)
print('cube_dict.keys():', cube_dict.keys())
print('cube_dict["F"].shape:', cube_dict["F"].shape)
print('len(cube_list):', len(cube_list))
print('cube_list[0].shape:', cube_list[0].shape)

Output:

cube_dice.shape: (768, 1024, 3)
cube_h.shape: (256, 1536, 3)
cube_dict.keys(): dict_keys(['F', 'R', 'B', 'L', 'U', 'D'])
cube_dict["F"].shape: (256, 256, 3)
len(cube_list): 6
cube_list[0].shape: (256, 256, 3)

Release files for py360convert 1.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py360convert 1.0.4
File Size Uploaded
py360convert-1.0.4.tar.gz 15.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for py360convert 1.0.4
File Interpreter ABI Platform
py360convert-1.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 30.3 kB

Release files / py360convert-1.0.4.tar.gz

Download URL py360convert-1.0.4.tar.gz
Size 15.0 kB
Tags Source
SHA-256 checksum
How to use checksums
bae75ae1d21351eb4aee556819219b01ed33ed9a75ff22ce443db17feb6769dc
BLAKE2b-256 checksum
How to use checksums
d020e5d263601c2a56d95f9c05adcb519a7cbf0fb478b03c91b939f364e5bf2d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.5 CPython/3.11.4 Darwin/24.4.0

Release files / py360convert-1.0.4-py3-none-any.whl

Download URL py360convert-1.0.4-py3-none-any.whl
Size 15.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fddb58443b9401a2741e05aae9da9e11ec9ea9e9e24511738ef8e0fa3ca069d8
BLAKE2b-256 checksum
How to use checksums
6a5bb035e2d71e8be8959196e90e4db7cc3896e39cadc3a083ad37a959c88988
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.5 CPython/3.11.4 Darwin/24.4.0

Release history Release notifications | RSS feed

This release

1.0.4 This release

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page