All Projects → haruishi43 → equilib

haruishi43 / equilib

Licence: AGPL-3.0 license
🌎→🗾Equirectangular (360/panoramic) image processing library for Python with minimal dependencies only using Numpy and PyTorch

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to equilib

pipano-sdk-ios
A Panorama SDK for iOS
Stars: ✭ 20 (-53.49%)
Mutual labels:  vr, panorama, 360
panorama
photo panorama converter
Stars: ✭ 52 (+20.93%)
Mutual labels:  panorama, equirectangular
Vue Vr
A framework for building VR applications with Vue
Stars: ✭ 348 (+709.3%)
Mutual labels:  vr, panorama
Panoramagl
PanoramaGL 全景展示(Xcode7~), fixed some issues,share to someone need it,support arm64
Stars: ✭ 127 (+195.35%)
Mutual labels:  vr, panorama
Openvslam
OpenVSLAM: A Versatile Visual SLAM Framework
Stars: ✭ 2,945 (+6748.84%)
Mutual labels:  vr, panorama
Image360
Special view & controller to display 360° panoramic images
Stars: ✭ 42 (-2.33%)
Mutual labels:  panorama, 360
natural-neighbor-interpolation
Fast, discrete natural neighbor interpolation in 3D on the CPU.
Stars: ✭ 63 (+46.51%)
Mutual labels:  numpy
python demo
一些简单有趣的Python小Demo
Stars: ✭ 109 (+153.49%)
Mutual labels:  numpy
WebSight
Aiding the visually impaired through real time augmented reality, AI object detection, WebGL shaders effects such as edge detection, and colour adjustments.
Stars: ✭ 26 (-39.53%)
Mutual labels:  vr
audiophile
Audio fingerprinting and recognition
Stars: ✭ 17 (-60.47%)
Mutual labels:  numpy
gau2grid
Fast computation of a gaussian and its derivative on a grid.
Stars: ✭ 23 (-46.51%)
Mutual labels:  numpy
Poke-Pi-Dex
Our deep learning for computer vision related project for nostalgic poke weebs (Sistemi digitali, Unibo).
Stars: ✭ 18 (-58.14%)
Mutual labels:  numpy
air writing
Online Hand Writing Recognition using BLSTM
Stars: ✭ 26 (-39.53%)
Mutual labels:  vr
lidar-buster
Collection of Python snippets for processing LiDAR point cloud.
Stars: ✭ 15 (-65.12%)
Mutual labels:  numpy
npbench
NPBench - A Benchmarking Suite for High-Performance NumPy
Stars: ✭ 40 (-6.98%)
Mutual labels:  numpy
icosa-viewer
3D Viewer component for Tilt Brush / Open Brush, Google Blocks files and their derivatives
Stars: ✭ 24 (-44.19%)
Mutual labels:  vr
vr-python-quickstart-hg1
VR Headset Controller Tutorial, get started with virtual reality in Python
Stars: ✭ 29 (-32.56%)
Mutual labels:  vr
vue-panorama
Panorama viewer for your homepage
Stars: ✭ 19 (-55.81%)
Mutual labels:  panorama
vrtist
Virtual Reality tool for storytelling
Stars: ✭ 43 (+0%)
Mutual labels:  vr
seapy
State Estimation and Analysis in Python
Stars: ✭ 25 (-41.86%)
Mutual labels:  numpy

equilib

Processing Equirectangular Images with Python

PyPI version GitHub license

equilib

  • A library for processing equirectangular image that runs on Python.
  • Developed using numpy and torch (c++ is WIP).
  • Able to use GPU for faster processing.
  • No need for other dependencies except for numpy and torch.
  • Added functionality like creating rotation matrices, batched processing, and automatic type detection.
  • Highly modular

If you found this module helpful to your project, please site this repository:

@software{pyequilib2021github,
  author = {Haruya Ishikawa},
  title = {PyEquilib: Processing Equirectangular Images with Python},
  url = {http://github.com/haruishi43/equilib},
  version = {0.5.0},
  year = {2021},
}

Installation:

Prerequisites:

  • Python (>=3.6)
  • Pytorch
pip install pyequilib

For developing, use:

git clone --recursive https://github.com/haruishi43/equilib.git
cd equilib

pip install -r requirements.txt

pip install -e .
# or
python setup.py develop

Basic Usage:

equilib has different transforms of equirectangular (or cubemap) images (note each transform has class and func APIs):

  • Cube2Equi/cube2equi: cubemap to equirectangular transform
  • Equi2Cube/equi2cube: equirectangular to cubemap transform
  • Equi2Equi/equi2equi: equirectangular transform
  • Equi2Pers/equi2pers: equirectangular to perspective transform

There are no real differences in class or func APIs:

  • class APIs will allow instantiating a class which you can call many times without having to specify configurations (class APIs call the func API)
  • func APIs are useful when there are no repetitive calls
  • both class and func APIs are extensible, so you can extend them to your use-cases or create a method that's more optimized (pull requests are welcome btw)

Each API automatically detects the input type (numpy.ndarray or torch.Tensor), and outputs are the same type.

An example for Equi2Pers/equi2pers:

Equi2Pers
equi2pers
import numpy as np
from PIL import Image
from equilib import Equi2Pers

# Input equirectangular image
equi_img = Image.open("./some_image.jpg")
equi_img = np.asarray(equi_img)
equi_img = np.transpose(equi_img, (2, 0, 1))

# rotations
rots = {
    'roll': 0.,
    'pitch': np.pi/4,  # rotate vertical
    'yaw': np.pi/4,  # rotate horizontal
}

# Intialize equi2pers
equi2pers = Equi2Pers(
    height=480,
    width=640,
    fov_x=90.0,
    mode="bilinear",
)

# obtain perspective image
pers_img = equi2pers(
    equi=equi_img,
    rots=rots,
)
import numpy as np
from PIL import Image
from equilib import equi2pers

# Input equirectangular image
equi_img = Image.open("./some_image.jpg")
equi_img = np.asarray(equi_img)
equi_img = np.transpose(equi_img, (2, 0, 1))

# rotations
rots = {
    'roll': 0.,
    'pitch': np.pi/4,  # rotate vertical
    'yaw': np.pi/4,  # rotate horizontal
}

# Run equi2pers
pers_img = equi2pers(
    equi=equi_img,
    rots=rots,
    height=480,
    width=640,
    fov_x=90.0,
    mode="bilinear",
)

For more information about how each APIs work, take a look in .readme or go through example codes in the tests or scripts.

Coordinate System:

Right-handed rule XYZ global coordinate system. x-axis faces forward and z-axis faces up.

  • roll: counter-clockwise rotation about the x-axis
  • pitch: counter-clockwise rotation about the y-axis
  • yaw: counter-clockwise rotation about the z-axis

You can chnage the right-handed coordinate system so that the z-axis faces down by adding z_down=True as a parameter.

See demo scripts under scripts.

Grid Sampling

To process equirectangular images fast, whether to crop perspective images from the equirectangular image, the library takes advantage of grid sampling techniques. Some sampling techniques are already implemented, such as scipy.ndimage.map_coordiantes and cv2.remap. This project's goal was to reduce these dependencies and use cuda and batch processing with torch and c++ for a faster processing of equirectangular images. There were not many projects online for these purposes. In this library, we implement varieties of methods using c++, numpy, and torch. This part of the code needs cuda acceleration because grid sampling is parallelizable. For torch, the built-in torch.nn.functional.grid_sample function is very fast and reliable. I have implemented a pure torch implementation of grid_sample which is very customizable (might not be fast as the native function). For numpy, I have implemented grid sampling methods that are faster than scipy and more robust than cv2.remap. Just like with this implementation of torch, numpy implementation is just as customizable. It is also possible to pass the scipy and cv2's grid sampling function through the use of override_func argument in grid_sample. Developing faster approaches and c++ methods are WIP. See here for more info on implementations.

Some notes:

  • By default, numpy's grid_sample will use pure numpy implementation. It is possible to override this implementation with scipy and cv2's implementation using override_func.
  • By default, torch's grid_sample will use the official implementation.
  • Benchmarking codes are stored in tests/. For example, benchmarking codes for numpy's equi2pers is located in tests/equi2pers/numpy_run_baselines.py and you can benchmark the runtime performance using different parameters against scipy and cv2.

Develop:

Test files for equilib are included under tests.

Running tests:

pytest tests

Note that I have added codes to benchmark every step of the process so that it is possible to optimize the code. If you find there are optimal ways of the implementation or bugs, all pull requests and issues are welcome.

Check CONTRIBUTING.md for more information

TODO:

  • Documentations for each transform
  • Add table and statistics for speed improvements
  • Batch processing for numpy
  • Mixed precision for torch
  • c++ version of grid sampling
  • More accurate intrinsic matrix formulation using vertial FOV for equi2pers
  • Multiprocessing support (slow when running on torch.distributed)

Acknowledgements:

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].