Skip to main content

A quick and easy to use library for reprojecting various image types

Project description

SphereSnap

A quick and easy to use library for reprojecting various image types. (inspired by http://paulbourke.net/panorama/sphere2persp/ )

Examples and usecases

Reprojecting equirectangular image into pinhole-camera images with customizable FoV and resolution

image image

Create equirectangular image using cubemap faces

image image

Create fisheye images from equirectangular or cubemap images

image

How to use it

import sphere_snap.utils as snap_utils
import sphere_snap.sphere_coor_projections as sphere_proj
from sphere_snap.snap_config import SnapConfig
from sphere_snap.sphere_snap import SphereSnap

Snap to perspective from equirectangular

snap_config = SnapConfig( [0,0,0,1], (1400,1400),(120,120), equi_img.shape[:2], source_img_type="equi")
snap_test = SphereSnap(snap_config)
persp_img = snap_test.snap_to_perspective(equi_img)

Reproject equirectangular into 6 planar images of 90 degrees FoV (Cubemap)

def get_cube_map_faces(face_size=1440, source_img_hw=(2000,4000), source_img_type="equi"):

    snap_configs = [SnapConfig( rot(90*i,0), (face_size,face_size),(90,90), source_img_hw, source_img_type=source_img_type)
                        for i in range(4)]
    # top
    snap_configs.append(SnapConfig( rot(0,90), (face_size,face_size),(90,90), source_img_hw, source_img_type=source_img_type))
    # bottom
    snap_configs.append(SnapConfig( rot(0,-90), (face_size,face_size),(90,90), source_img_hw, source_img_type=source_img_type))
    return snap_configs

cube_configs = get_cube_map_faces(face_size=1440, source_img_hw=equi_img.shape[:2])
cube_faces_snaps = [SphereSnap(c) for c in cube_configs]
cumbe_faces_imgs = [snap.snap_to_perspective(equi_img) for snap in cube_faces_snaps]

Reproject a planar image into equirectangular

reconstructed_equi = SphereSnap.merge_multiple_snaps((1000,2000), 
                                                     cube_faces_snaps, # snap object specifies destination position
                                                     cumbe_faces_imgs[::-1], # snap image contains planar image pixels
                                                     target_type="equi", # destination image type
                                                     merge_method="max")

Reproject a planar image into fisheye 180

reconstructed_fisheye = SphereSnap.merge_multiple_snaps((1000,1000), 
                                                    cube_faces_snaps, # snap object specifies destination position
                                                    cumbe_faces_imgs, # snap image contains planar image pixels
                                                    target_type="fisheye180", # destination image type
                                                    merge_method="max")                                                    

Snap to perspective from fisheye 180

snap_config = SnapConfig( rot(45,1), (1400,1400),(100,100), reconstructed_fisheye.shape[:2], source_img_type="fisheye180")
snap_test = SphereSnap(snap_config)
persp_img = snap_test.snap_to_perspective(reconstructed_fisheye)

Reproject fisheye 180 to equirectangular

snap_configs = [SnapConfig( rot(yaw,pitch), (800,800),(90,90), fisheye180_img.shape[:2], source_img_type="fisheye180") 
                    for yaw,pitch in [[-45,-45],[45,-45],[-45,45],[45,45],[0,0]]]
snaps = [SphereSnap(c) for c in snap_configs]
snap_imgs = [snap.snap_to_perspective(fisheye180_img) for snap in snaps]

reconstructed_equi = SphereSnap.merge_multiple_snaps((1000,2000), 
                                                     snaps, # snap object specifies destination position
                                                     snap_imgs, # snap image contains planar image pixels
                                                     target_type="equi", # destination image type
                                                     merge_method="max")

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

sphere_snap-1.0.0-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file sphere_snap-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: sphere_snap-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 17.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.5

File hashes

Hashes for sphere_snap-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 65cca40c5b4e03326ba3847075788075ff0f4a8b2937a5f1ddb14252e11543d5
MD5 5c5a5fbe3465f21380e31a9e65fc6879
BLAKE2b-256 9c524bdea3fa9b9e890f00acf07d07e4ecf13b4082a9fa05f8d957183d8f88cf

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