soravux / skylibs Goto Github PK
View Code? Open in Web Editor NEWPython library to handle 360° environment maps
License: GNU Lesser General Public License v3.0
Python library to handle 360° environment maps
License: GNU Lesser General Public License v3.0
The functions cube2world and world2cube have non-uniform operating characteristics to other projection functions. Input/Output should match, as either floats or arrays respectively.
cube2world processes only arrays:
>>> env.projections.cube2world(np.array([0.5]),np.array([0.5]))
(array([0.]), array([-0.70710678]), array([-0.70710678]), array([ True]))
cube2world fails to parse float input:
>>> env.projections.cube2world(0,0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/iamaq/.local/lib/python3.10/site-packages/envmap/projections.py", line 232, in cube2world
x = np.zeros(u.shape)
world2cube returns arrays for float inputs:
>>> env.projections.world2cube(0.5,.5,0.5)
(array([1.]), array([0.25]))
It needs to be verified that the 90 degree orientation offset is universal (as implemented) or specific to skydb. If it's the later, the code should be altered to accept a desired offset.
Line 100 in adb148d
Missing transformation from normalized uv coordinates space to pixel UV coordinates is causing frequent error, even within skylibs.
problem:
example 1D pixel space as array of size n=8
x_ = np.linspace(0,7,8, dtype=int)
gives discrete coordinates = array([0, 1, 2, 3, 4, 5, 6, 7])
example 1D normalized space as array of size n=8
x = np.linspace(0,1,(2*8)+1);
x=x[1::2]
gives normalized coordinates = array([0.0625, 0.1875, 0.3125, 0.4375, 0.5625, 0.6875, 0.8125, 0.9375])
as such, defining x = x_ / n
as done in the erroneous sample from skylibs below
x_ = np.linspace(0,7,8, dtype=int); x = x_/8
gives normalized coordinates array([0. , 0.125, 0.25 , 0.375, 0.5 , 0.625, 0.75 , 0.875])
which in an invalid distribution of the normalized space
c = findBrightestSpot(envmapInput.data)
u, v = c[1] / envmapInput.data.shape[1], c[0] / envmapInput.data.shape[0]
pixels are not centered properly in normalized coordinate space
Hello @soravux,
It seems there's a little incoherence when resizing an environment map using the resize()
method.
I have 2048x1024 images that I'm trying to resize to 256x256 but even when I pass a tuple to the resize()
method I get a 512x256 result instead. This is due to the fact that the code checks if the original height is divisible by the new one (here), but then applies the same downscaling factor for both the height and the width (here). Is this the intended behaviour (given that when the divisibility condition isn't met, the target height and width are both respected here)?
Thanks in advance for your response!
Can be done using dcraw:
dcraw -v -4 -T -t 0 -j filename.CR2
Check also the ImageMagick Python wrappers.
Hi! This keeps printing '3' when using this funcion.
Line 52 in b39bc34
downscaleEnvmap(...) produces an needle-like artifact in downsizing operation.
Artifact, as observed on a skyangular image (converted from latlong skydome):
Artifact, as observed on a synthetic (ones) skyangular image (converted from synthetic (ones) latlong ):
Code to reproduce:
# OS tools
import os
os.environ["OPENCV_IO_ENABLE_OPENEXR"]="1" # Enable EXR
# Machine vision tools
import cv2
import numpy as np
from envmap import EnvironmentMap
def downscaleEnvmap(nenvmap, sao, sat, times):
"""Energy-preserving environment map downscaling by factors of 2.
Usage:
sao = EnvironmentMap(512, 'LatLong').solidAngles() # Source envmap solid angles, could be replaced by `sao = envmap.soldAngles()`
sat = EnvironmentMap(128, 'LatLong').solidAngles() # Target envmap solid angles
downscaleEnvmap(envmap, sao, sat, 3)
Note : `times` is the number of downscales, so the total downscaling factor is 2**times"""
nenvmap.data *= sao[:, :, np.newaxis]
nenvmap.data = np.pad(nenvmap.data, [(0, 1), (0, 1), (0, 0)], 'constant')
sx = np.cumsum(nenvmap.data, axis=1)
tmp = sx[:, 2**times::2**times, ...] - sx[:, :-2**times:2**times, ...]
sy = np.cumsum(tmp, axis=0)
nenvmap.data = sy[2**times::2**times, :, ...] - sy[:-2**times:2**times, :, ...]
if nenvmap.data.shape[1] > 2*nenvmap.data.shape[0]:
nenvmap.data[:, -2, :] += nenvmap[:, -1, :]
nenvmap.data = nenvmap.data[:, :-1, :]
nenvmap.data /= sat[:, :, np.newaxis]
nenvmap.data = np.ascontiguousarray(nenvmap.data)
return nenvmap
## ---- envmap Sample ---- ##
print("-> Loading image sample")
img_path = "unzipped_envmap/20141003_130155_envmap.exr"
img_latlong = cv2.imread(img_path, cv2.IMREAD_UNCHANGED)
cv2.imwrite("img_latlong_original.exr", img_latlong)
# Create Envmap
e_ll = EnvironmentMap(np.copy(img_latlong), 'latlong')
cv2.imwrite("e_ll.exr", e_ll.data.astype(np.float32))
# Convert Envmap to Skyangular
e_sa = EnvironmentMap(np.copy(img_latlong), 'latlong').convertTo('skyangular')
cv2.imwrite("e_sa.exr", e_sa.data.astype(np.float32))
# Convert Envmap to Skyangular
e_sa = EnvironmentMap(np.copy(img_latlong), 'latlong').convertTo('skyangular', 512)
cv2.imwrite("e_sa512.exr", e_sa.data.astype(np.float32))
# Downscale
sao = e_ll.solidAngles()
sat = EnvironmentMap(512, 'Latlong').solidAngles()
e_llD = downscaleEnvmap(e_ll, sao, sat, 1)
cv2.imwrite("e_ll512D.exr", e_llD.data.astype(np.float32))
# Convert Envmap to Skyangular
e_saD = e_llD.convertTo('skyangular')
cv2.imwrite("e_sa512D.exr", e_saD.data.astype(np.float32))
## ---- Synthetic Sample ---- ##
print("-> Creating grey-image sample")
img_latlong = np.zeros((1024, 2048,3), np.float64) +1
# img_latlong[int(img_latlong.shape[0]/2):, :]=0
# img_latlong[::2, 1::2]=0
# Create Envmap
e_ll = EnvironmentMap(np.copy(img_latlong), 'latlong')
# Downscale
sao = e_ll.solidAngles()
sat = EnvironmentMap(512, 'Latlong').solidAngles()
e_llD = downscaleEnvmap(e_ll, sao, sat, 1)
cv2.imwrite("e_ll512D_synthetic.exr", e_llD.data.astype(np.float32))
# Convert Envmap to Skyangular
e_saD = e_llD.convertTo('skyangular')
cv2.imwrite("e_sa512D_synthetic.exr", e_saD.data.astype(np.float32))
'''
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.