All Projects → sunset1995 → Py360convert

sunset1995 / Py360convert

Licence: mit
Python implementation of convertion between equirectangular, cubemap and perspective. (equirect2cube, cube2equirect, equirect2perspec)

Programming Languages

python
139335 projects - #7 most used programming language

Labels

Projects that are alternatives of or similar to Py360convert

Word To Markdown
A ruby gem to liberate content from Microsoft Word documents
Stars: ✭ 1,216 (+976.11%)
Mutual labels:  converter
Wx Voice
Convert audio files between Tencent apps (Weixin / Wechat, QQ) and Silk codec with other general formats such as MP3 and M4A
Stars: ✭ 93 (-17.7%)
Mutual labels:  converter
Pkhex.mobile
Pokémon save editor on the go!
Stars: ✭ 101 (-10.62%)
Mutual labels:  converter
Jalali.py
Persian and Gregorian Date Converter for Python 2 and Python 3
Stars: ✭ 82 (-27.43%)
Mutual labels:  converter
Html To Markdown
Convert HTML to Markdown with PHP
Stars: ✭ 1,293 (+1044.25%)
Mutual labels:  converter
Av Converter
[av-converter.com] Audio and Video Converter, and YouTube downloader. Convert to MP3, MP4, AAC, FLAC, AC3, WAV, etc.
Stars: ✭ 97 (-14.16%)
Mutual labels:  converter
Seonbi
SmartyPants for Korean language
Stars: ✭ 76 (-32.74%)
Mutual labels:  converter
Json Node Normalizer
'json-node-normalizer' - NodeJS module that normalize json data types from json schema specifications.
Stars: ✭ 105 (-7.08%)
Mutual labels:  converter
Alfred Calculate Anything
Alfred Workflow to calculate anything with natural language
Stars: ✭ 92 (-18.58%)
Mutual labels:  converter
Ffmpeg Gif Script For Bash
Turn your videos into palette-mapped gifs with this easy script
Stars: ✭ 100 (-11.5%)
Mutual labels:  converter
Fb2converter
Unified converter of FB2 files into epub2, kepub, mobi and azw3 formats.
Stars: ✭ 83 (-26.55%)
Mutual labels:  converter
Png To Ico
convert png to ico format
Stars: ✭ 88 (-22.12%)
Mutual labels:  converter
Kramdown Asciidoc
A kramdown extension for converting Markdown documents to AsciiDoc.
Stars: ✭ 97 (-14.16%)
Mutual labels:  converter
Perun
A command-line validation tool for AWS Cloud Formation that allows to conquer the cloud faster!
Stars: ✭ 82 (-27.43%)
Mutual labels:  converter
Guardonce
Utilities for converting from C/C++ include guards to #pragma once and back again.
Stars: ✭ 103 (-8.85%)
Mutual labels:  converter
Currencyconverter
Utilities for doing currency conversion with the Money library
Stars: ✭ 78 (-30.97%)
Mutual labels:  converter
Epoch
A simple but powerful Epoch converter
Stars: ✭ 94 (-16.81%)
Mutual labels:  converter
Ec2 Spot Converter
A tool to convert AWS EC2 instances back and forth between On-Demand and Spot billing models.
Stars: ✭ 108 (-4.42%)
Mutual labels:  converter
I7j Pdfhtml
pdfHTML is an iText 7 add-on for Java that allows you to easily convert HTML and CSS into standards compliant PDFs that are accessible, searchable and usable for indexing.
Stars: ✭ 104 (-7.96%)
Mutual labels:  converter
Lambda Converters
Strongly-typed lambda expressions as value converters, data template selectors, and validation rules
Stars: ✭ 99 (-12.39%)
Mutual labels:  converter

py360convert

A new library including more fuctionality for 360 is under contruction by my colleague. This repo will be depreciated then.

Features of this project:

  • Convertion between cubemap and equirectangular
  • Equirectangular to planar
  • Pure python implementation and depend only on numpy and scipy
  • Vectorization implementation (in most of the place)
    • c2e takes 300ms and e2c takes 160ms on 1.6 GHz Intel Core i5 CPU

Requirements

  • numpy
  • scipy
  • pillow (for example code to load/save image)

Install

pip install py360convert

Now at everywhere, you can import py360convert or use the command line tool convert360.

Command line examples

You can run command line tool to use the functionality. Please See convert360 -h for detailed. The python script is also an example code to see how to use this as a package in your code.

convert360 --convert e2c --i assert/example_input.png --o assert/example_e2c.png --w 200
Input Equirectangular Output Cubemap

convert360 --convert c2e --i assert/example_e2c.png --o assert/example_c2e.png --w 800 --h 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 --convert e2p --i assert/example_input.png --o assert/example_e2p.png --w 300 --h 300 --u_deg 120 --v_deg 23
Input Equirectangular Output Perspective

Doc

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

Convert the given equirectangular to cubemap.
Parameters:

  • e_img: Numpy array with shape [H, W, C].
  • face_w: The width of each cube face.
  • mode: bilinear or nearest.
  • cube_format: See c2e explaination.

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.

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.
  • cube_format: 'dice' (default) or 'horizon' or 'dict' or 'list'. Telling 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 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 question about the conversion between formats.

Example:

import numpy as np
from PIL import Image
import py360convert

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

# You can make convertion 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)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].