Skip to content

Commit

Permalink
Format "colour_hdri" package.
Browse files Browse the repository at this point in the history
  • Loading branch information
KelSolaar committed Jul 4, 2017
1 parent 7f5c6f3 commit 86bc31b
Show file tree
Hide file tree
Showing 43 changed files with 1,107 additions and 1,445 deletions.
19 changes: 9 additions & 10 deletions colour_hdri/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Colour - HDRI
=============
Expand Down Expand Up @@ -60,18 +59,18 @@
__all__ += recovery.__all__
__all__ += tonemapping.__all__

RESOURCES_DIRECTORY = os.path.join(
os.path.dirname(__file__), 'resources')
EXAMPLES_RESOURCES_DIRECTORY = os.path.join(
RESOURCES_DIRECTORY, 'colour-hdri-examples-dataset')
TESTS_RESOURCES_DIRECTORY = os.path.join(
RESOURCES_DIRECTORY, 'colour-hdri-tests-dataset')
RESOURCES_DIRECTORY = os.path.join(os.path.dirname(__file__), 'resources')
EXAMPLES_RESOURCES_DIRECTORY = os.path.join(RESOURCES_DIRECTORY,
'colour-hdri-examples-dataset')
TESTS_RESOURCES_DIRECTORY = os.path.join(RESOURCES_DIRECTORY,
'colour-hdri-tests-dataset')

__application_name__ = 'Colour - HDRI'

__major_version__ = '0'
__minor_version__ = '1'
__change_version__ = '3'
__version__ = '.'.join((__major_version__,
__minor_version__,
__change_version__))
__version__ = '.'.join(
(__major_version__,
__minor_version__,
__change_version__)) # yapf: disable
6 changes: 4 additions & 2 deletions colour_hdri/calibration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
absolute_luminance_calibration_Lagarde2016)
from .debevec1997 import g_solve, camera_response_functions_Debevec1997

__all__ = ['upper_hemisphere_illuminance_weights_Lagarde2016',
'absolute_luminance_calibration_Lagarde2016']
__all__ = [
'upper_hemisphere_illuminance_weights_Lagarde2016',
'absolute_luminance_calibration_Lagarde2016'
]
__all__ += ['g_solve', 'camera_response_functions_Debevec1997']
20 changes: 9 additions & 11 deletions colour_hdri/calibration/absolute_luminance.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Absolute Luminance Calibration - Lagarde (2016)
===============================================
Expand Down Expand Up @@ -33,14 +32,15 @@
__email__ = 'colour-science@googlegroups.com'
__status__ = 'Production'

__all__ = ['upper_hemisphere_illuminance_Lagarde2016',
'upper_hemisphere_illuminance_weights_Lagarde2016',
'absolute_luminance_calibration_Lagarde2016']
__all__ = [
'upper_hemisphere_illuminance_Lagarde2016',
'upper_hemisphere_illuminance_weights_Lagarde2016',
'absolute_luminance_calibration_Lagarde2016'
]


def upper_hemisphere_illuminance_Lagarde2016(
RGB,
colourspace=RGB_COLOURSPACES['sRGB']):
RGB, colourspace=RGB_COLOURSPACES['sRGB']):
"""
Computes upper hemisphere illuminance :math:`E_v` of given RGB panoramic
image.
Expand Down Expand Up @@ -129,16 +129,14 @@ def upper_hemisphere_illuminance_weights_Lagarde2016(height, width):
theta_cos = np.cos(theta)
theta_sin = np.sin(theta)

w[theta_cos > 0] = (theta_cos[theta_cos > 0] * theta_sin[theta_cos > 0] *
2 * np.pi ** 2)
w[theta_cos > 0] = (
theta_cos[theta_cos > 0] * theta_sin[theta_cos > 0] * 2 * np.pi ** 2)

return w


def absolute_luminance_calibration_Lagarde2016(
RGB,
measured_illuminance,
colourspace=RGB_COLOURSPACES['sRGB']):
RGB, measured_illuminance, colourspace=RGB_COLOURSPACES['sRGB']):
"""
Performs absolute *Luminance* calibration of given *RGB* panoramic image
using *Lagarde (2016)* method.
Expand Down
16 changes: 7 additions & 9 deletions colour_hdri/calibration/debevec1997.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Debevec (1997) Camera Response Function Computation
===================================================
Expand Down Expand Up @@ -39,8 +38,7 @@
__email__ = 'colour-science@googlegroups.com'
__status__ = 'Production'

__all__ = ['g_solve',
'camera_response_functions_Debevec1997']
__all__ = ['g_solve', 'camera_response_functions_Debevec1997']


def g_solve(Z, B, l=30, w=weighting_function_Debevec1997, n=256):
Expand Down Expand Up @@ -146,14 +144,14 @@ def camera_response_functions_Debevec1997(image_stack,
Camera response functions :math:`g(z)`.
"""

samples = s(image_stack.data, samples, n)
s_o = s(image_stack.data, samples, n)

L_l = np.log(average_luminance(image_stack.f_number,
image_stack.exposure_time,
image_stack.iso))
L_l = np.log(
average_luminance(image_stack.f_number, image_stack.exposure_time,
image_stack.iso))

crfs = np.exp(tstack(np.array([g_solve(samples[..., x], L_l, l, w, n)[0]
for x in range(samples.shape[-1])])))
g_c = [g_solve(s_o[..., x], L_l, l, w, n)[0] for x in range(s_o.shape[-1])]
crfs = np.exp(tstack(np.array(g_c)))

if normalise:
# TODO: Investigate if the normalisation value should account for the
Expand Down
38 changes: 19 additions & 19 deletions colour_hdri/calibration/tests/tests_absolute_luminance.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# !/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Defines unit tests for :mod:`colour_hdri.calibration.absolute_luminance`
module.
Expand Down Expand Up @@ -28,15 +27,16 @@
__email__ = 'colour-science@googlegroups.com'
__status__ = 'Production'

__all__ = ['TestUpperHemisphereIlluminanceLagarde2016',
'TestUpperHemisphereIlluminanceWeightsLagarde2016',
'TestAbsoluteLuminanceCalibrationLagarde2016']
__all__ = [
'TestUpperHemisphereIlluminanceLagarde2016',
'TestUpperHemisphereIlluminanceWeightsLagarde2016',
'TestAbsoluteLuminanceCalibrationLagarde2016'
]

UNITY_001_DIRECTORY = os.path.join(
TESTS_RESOURCES_DIRECTORY, 'unity_001')
UNITY_001_DIRECTORY = os.path.join(TESTS_RESOURCES_DIRECTORY, 'unity_001')

CALIBRATION_DIRECTORY = os.path.join(
TESTS_RESOURCES_DIRECTORY, 'colour_hdri', 'calibration')
CALIBRATION_DIRECTORY = os.path.join(TESTS_RESOURCES_DIRECTORY, 'colour_hdri',
'calibration')


class TestUpperHemisphereIlluminanceLagarde2016(unittest.TestCase):
Expand All @@ -52,8 +52,7 @@ def test_upper_hemisphere_illuminance_Lagarde2016(self):
"""

self.assertAlmostEqual(
upper_hemisphere_illuminance_Lagarde2016(
np.ones((16, 32, 3))),
upper_hemisphere_illuminance_Lagarde2016(np.ones((16, 32, 3))),
2.934469165342606,
places=7)

Expand Down Expand Up @@ -115,7 +114,7 @@ def test_upper_hemisphere_illuminance_weights_Lagarde2016(self):
[0.00000000],
[0.00000000],
[0.00000000],
[0.00000000]])
[0.00000000]]) # yapf: disable

np.testing.assert_almost_equal(
upper_hemisphere_illuminance_weights_Lagarde2016(32, 16),
Expand All @@ -141,18 +140,19 @@ def test_absolute_luminance_calibration_Lagarde2016(self):
# Treasure Island - white balanced.exr

reference_exr_file = read_image(
str(os.path.join(
UNITY_001_DIRECTORY,
'Unity_Treasure_Island_White_Balanced.exr')))
str(
os.path.join(UNITY_001_DIRECTORY,
'Unity_Treasure_Island_White_Balanced.exr')))

test_exr_file = read_image(
str(os.path.join(
CALIBRATION_DIRECTORY,
'Unity_Treasure_Island_White_Balanced_Absolute.exr')))
str(
os.path.join(
CALIBRATION_DIRECTORY,
'Unity_Treasure_Island_White_Balanced_Absolute.exr')))

np.testing.assert_allclose(
absolute_luminance_calibration_Lagarde2016(
reference_exr_file, 51000),
absolute_luminance_calibration_Lagarde2016(reference_exr_file,
51000),
test_exr_file,
rtol=0.0000001,
atol=0.0000001)
Expand Down
50 changes: 24 additions & 26 deletions colour_hdri/calibration/tests/tests_debevec1997.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# !/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Defines unit tests for :mod:`colour_hdri.calibration.debevec1997` module.
"""
Expand All @@ -12,9 +11,8 @@
import unittest

from colour_hdri import TESTS_RESOURCES_DIRECTORY
from colour_hdri.calibration import (
g_solve,
camera_response_functions_Debevec1997)
from colour_hdri.calibration import (g_solve,
camera_response_functions_Debevec1997)
from colour_hdri.sampling import samples_Grossberg2003
from colour_hdri.utilities import ImageStack, average_luminance, filter_files

Expand All @@ -25,19 +23,18 @@
__email__ = 'colour-science@googlegroups.com'
__status__ = 'Production'

__all__ = ['FROBISHER_001_DIRECTORY',
'CALIBRATION_DIRECTORY',
'JPG_IMAGES',
'TestGSolve',
'TestCameraResponseFunctionsDebevec1997']
__all__ = [
'FROBISHER_001_DIRECTORY', 'CALIBRATION_DIRECTORY', 'JPG_IMAGES',
'TestGSolve', 'TestCameraResponseFunctionsDebevec1997'
]

FROBISHER_001_DIRECTORY = os.path.join(
TESTS_RESOURCES_DIRECTORY, 'frobisher_001')
FROBISHER_001_DIRECTORY = os.path.join(TESTS_RESOURCES_DIRECTORY,
'frobisher_001')

CALIBRATION_DIRECTORY = os.path.join(
TESTS_RESOURCES_DIRECTORY, 'colour_hdri', 'calibration')
CALIBRATION_DIRECTORY = os.path.join(TESTS_RESOURCES_DIRECTORY, 'colour_hdri',
'calibration')

JPG_IMAGES = filter_files(FROBISHER_001_DIRECTORY, ('jpg',))
JPG_IMAGES = filter_files(FROBISHER_001_DIRECTORY, ('jpg', ))


class TestGSolve(unittest.TestCase):
Expand All @@ -52,9 +49,9 @@ def test_g_solve(self):
"""

image_stack = ImageStack.from_files(JPG_IMAGES)
L_l = np.log(average_luminance(image_stack.f_number,
image_stack.exposure_time,
image_stack.iso))
L_l = np.log(
average_luminance(image_stack.f_number, image_stack.exposure_time,
image_stack.iso))
samples = samples_Grossberg2003(image_stack.data)

for i in range(3):
Expand All @@ -63,18 +60,18 @@ def test_g_solve(self):
# Lower precision for unit tests under *travis-ci*.
np.testing.assert_allclose(
g[0:-2],
np.load(os.path.join(
CALIBRATION_DIRECTORY,
'test_g_solve_g_{0}.npy'.format(i)))[0:-2],
np.load(
os.path.join(CALIBRATION_DIRECTORY,
'test_g_solve_g_{0}.npy'.format(i)))[0:-2],
rtol=0.001,
atol=0.001)

# Lower precision for unit tests under *travis-ci*.
np.testing.assert_allclose(
lE[1:],
np.load(os.path.join(
CALIBRATION_DIRECTORY,
'test_g_solve_lE_{0}.npy'.format(i)))[1:],
np.load(
os.path.join(CALIBRATION_DIRECTORY,
'test_g_solve_lE_{0}.npy'.format(i)))[1:],
rtol=0.001,
atol=0.001)

Expand All @@ -95,9 +92,10 @@ def test_camera_response_function_Debevec1997(self):
np.testing.assert_allclose(
camera_response_functions_Debevec1997(
ImageStack.from_files(JPG_IMAGES)),
np.load(os.path.join(
CALIBRATION_DIRECTORY,
'test_camera_response_function_Debevec1997_crfs.npy')),
np.load(
os.path.join(
CALIBRATION_DIRECTORY,
'test_camera_response_function_Debevec1997_crfs.npy')),
rtol=0.00001,
atol=0.00001)

Expand Down
13 changes: 6 additions & 7 deletions colour_hdri/generation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@

from __future__ import absolute_import

from .weighting_functions import (
normal_distribution_function,
hat_function,
weighting_function_Debevec1997)
from .weighting_functions import (normal_distribution_function, hat_function,
weighting_function_Debevec1997)
from .radiance import image_stack_to_radiance_image

__all__ = []
__all__ += ['normal_distribution_function',
'hat_function',
'weighting_function_Debevec1997']
__all__ += [
'normal_distribution_function', 'hat_function',
'weighting_function_Debevec1997'
]
__all__ += ['image_stack_to_radiance_image']
16 changes: 6 additions & 10 deletions colour_hdri/generation/radiance.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
HDRI / Radiance Image Generation
================================
Expand Down Expand Up @@ -84,17 +83,14 @@ def image_stack_to_radiance_image(
image_c = np.zeros(image.data.shape)
weight_c = np.zeros(image.data.shape)

L = average_luminance(
image.metadata.f_number,
image.metadata.exposure_time,
image.metadata.iso)
L = average_luminance(image.metadata.f_number,
image.metadata.exposure_time, image.metadata.iso)

if np.any(image.data <= 0):
warning(
'"{0}" image channels contain negative or equal to zero '
'values, unpredictable results may occur! Please consider '
'encoding your images in a wider gamut RGB colourspace or '
'clamp negative values.'.format(image.path))
warning('"{0}" image channels contain negative or equal to zero '
'values, unpredictable results may occur! Please consider '
'encoding your images in a wider gamut RGB colourspace or '
'clamp negative values.'.format(image.path))

if weighting_average and image.data.ndim == 3:
average = np.average(image.data, axis=-1)
Expand Down

0 comments on commit 86bc31b

Please sign in to comment.