Skip to content
This repository was archived by the owner on Jan 22, 2023. It is now read-only.

Commit 83f42c0

Browse files
committed
changed equalization method
1 parent 6da487f commit 83f42c0

File tree

4 files changed

+36
-20
lines changed

4 files changed

+36
-20
lines changed

imgutils.py

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,28 @@
33

44
import numpy as np
55

6-
class EncodingSettings:
6+
class ColorEncodingSettings:
77
def __init__(self):
8+
9+
## Color endcoding pipeline
10+
11+
# First the intensity values are shifted downwards so that this
12+
# reference point has zero brightness = (r+g+b)/3
13+
self.low_normalization = np.min
14+
15+
# Then the values are scaled linearly so that this reference
16+
# point becomes equal to the below brightness value
17+
self.brightness_reference = np.mean
18+
self.brightness = 0.4
19+
20+
# Then gamma correction x -> x^(1/gamma) is applied
821
self.gamma = 1.8
9-
self.brightness = 0.3
10-
self.normalization = 'mean'
11-
self.equalize = True
22+
23+
# If set, over-exposed values are blurred with a flare effect
1224
self.flares = False
25+
26+
# Finally, all color values are clamped to range [0,1] and
27+
# encoded using 8-bit
1328

1429
class Image:
1530

@@ -19,7 +34,7 @@ def __init__( self, npy_filename = None, data = None, settings = None ):
1934
else:
2035
self.data = np.load( npy_filename )
2136

22-
if settings is None: settings = EncodingSettings()
37+
if settings is None: settings = ColorEncodingSettings()
2338
self.settings = settings
2439

2540
self._pgwin = None
@@ -41,21 +56,23 @@ def _sum( self, imgdata ):
4156

4257
def _to_24bit( self, imgdata = None ):
4358
imgdata = np.nan_to_num(self._sum( imgdata ))
44-
ref = getattr(np, self.settings.normalization)(imgdata)
59+
lightness = np.ravel(np.mean(imgdata, 2))
60+
61+
lo_norm = self.settings.low_normalization
62+
if lo_norm is not None and lo_norm is not 0:
63+
min_l = lo_norm(lightness)
64+
imgdata -= min_l
65+
lightness -= min_l
66+
67+
ref = self.settings.brightness_reference(lightness)
4568

4669
imgdata = np.clip(imgdata/ref*self.settings.brightness, 0, None)
4770
imgdata = np.power(imgdata, 1.0/self.settings.gamma)
71+
4872
if self.settings.flares:
4973
imgdata = flares(imgdata)
74+
5075
imgdata = np.clip(imgdata, 0, 1.0)
51-
if self.settings.equalize:
52-
lightness = np.mean(imgdata, 2)
53-
min_l = np.min(lightness)
54-
max_l = np.max(lightness)
55-
56-
if min_l != max_l:
57-
imgdata = (imgdata - min_l) / (max_l - min_l)
58-
imgdata = np.clip(imgdata, 0, 1.0)
5976

6077
return (imgdata*255).astype(np.uint8)
6178

scene.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import numpy as np
22
import camera
3-
from imgutils import EncodingSettings
3+
from imgutils import ColorEncodingSettings
44

55
class Scene:
66
"""
@@ -21,7 +21,7 @@ def __init__(self, tracer, material, name=None):
2121
self.name = name
2222
self.bidirectional_light = False
2323

24-
class ImageSettings(EncodingSettings):
24+
class ImageSettings(ColorEncodingSettings):
2525
pass
2626

2727
def get_camera_rotmat(self):

scenes/default_scenes.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,6 @@ def default_settings(scene):
8282
# --- Image settings
8383
scene.image = Scene.ImageSettings()
8484
scene.image.size = (800, 600)
85-
scene.image.brightness = 0.3
86-
scene.image.gamma = 1.8
87-
scene.image.brightness_reference = 'mean'
88-
scene.image.equalize = True
8985

9086
# --- Raytracer settings
9187
scene.tent_filter = True

scenes/scene-test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,7 @@ def load_triangle_mesh_in_octree(p, R, **kwargs):
103103
scene.max_bounces = 4
104104
scene.min_bounces = 2
105105

106+
scene.image.brighness_reference = numpy.max
107+
scene.brightness = 1.0
108+
106109
scene.direct_camera_towards((0,0,0.0))

0 commit comments

Comments
 (0)