Skip to main content

equirectangular image processing with python

Project description

equilib

Processing Equirectangular Images with Python

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

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

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
rot = {
    'roll': 0.,
    'pitch': np.pi/4,  # rotate vertical
    'yaw': np.pi/4,  # rotate horizontal
}

# Intialize equi2pers
equi2pers = Equi2Pers(
    w_pers=640,
    h_pers=480,
    fov_x=90,
    skew=0.0,
    sampling_method="default",
    mode="bilinear",
)

# obtain perspective image
pers_img = equi2pers(
    equi=equi_img,
    rot=rot,
)
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
rot = {
    'roll': 0.,
    'pitch': np.pi/4,  # rotate vertical
    'yaw': np.pi/4,  # rotate horizontal
}

# Intialize equi2pers
pers_img = equi2pers(
    equi=equi_img,
    rot=rot,
    w_pers=640,
    h_pers=480,
    fov_x=90,
    skew=0.0,
    sampling_method="default",
    mode="bilinear",
)

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

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

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 pytorch 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 pytorch. This part of the code needs cuda acceleration because grid sampling is parallelizable. For c++ and pytorch, I tried to take advantage of cuda. For numpy, I implemented naive and faster approaches for learning purposes. Developing faster c++ and pytorch approaches are WIP. Currently, sampling_method defaults to the fastest methods which are named "default". See here for more info on implementations.

Develop:

Test files for equilib are included under tests.

Running tests:

pytest tests

Check CONTRIBUTING.md for more information

TODO:

  • Documentations for each transform
  • Add graphs and statistics for speed improvements

Acknowledgements:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyequilib-0.2.0.tar.gz (26.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyequilib-0.2.0-py3-none-any.whl (48.4 kB view details)

Uploaded Python 3

File details

Details for the file pyequilib-0.2.0.tar.gz.

File metadata

  • Download URL: pyequilib-0.2.0.tar.gz
  • Upload date:
  • Size: 26.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1

File hashes

Hashes for pyequilib-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f06122a9a2307715e6b6005b5720b6905d86e62d7387f3bca3a60946b3704bc4
MD5 16e4811888009f9e365b590da56da820
BLAKE2b-256 ecabadf3a74dda685f405f4220301e7bfc0f2c905bcb1b89ef0c7b7b835b7015

See more details on using hashes here.

File details

Details for the file pyequilib-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pyequilib-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 48.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1

File hashes

Hashes for pyequilib-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 227fe9d4f4b45949543251914e0be643e33393259bcd01ed4b2479a2711c6621
MD5 883922ec7c082b43a3a675fbb63f5494
BLAKE2b-256 41496d9d0cc2cabde27d27d84d52f78c39c97ee341eb9a8ebba826339ec174f1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page