soravux / skylibs

Python library to handle 360° environment maps
GNU Lesser General Public License v3.0
86 stars 29 forks source link

UV pixels missmatched with normalized uv space #31

Closed IanMaquignaz closed 1 year ago

IanMaquignaz commented 1 year ago

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 / nas 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

Example error within skylibs:

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