Skip to content

Commit

Permalink
feat: auto expose each image to 18% grey
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe-Heffer-Shef committed Jun 17, 2024
1 parent fbe4b27 commit d79c0b7
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions backend/btviewer/blueprints/photo/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,16 @@ def data(self) -> Mapping:
def array(self):
return self.get_array()

def get_array(self, scale_factor: float = None, dtype=numpy.dtype('uint8')) -> numpy.array:
def get_array(self, scale_factor: float = None, dtype=numpy.dtype('uint8'),
mean_exposure: float = 0.18) -> numpy.array:
"""
2D image data array of pixel values.
By default, this produces a normalised 2D grid of unsigned 8-bit integers (0 to 255).
:param scale_factor: Multiplication factor for the pixel brightness values
:param dtype: Data type https://numpy.org/doc/stable/reference/generated/numpy.ndarray.astype.html
:param mean_exposure: The target average brightness (default 1to 18% grey)
"""
# Set data type for array values
dtype = numpy.dtype(dtype)
Expand All @@ -167,8 +169,8 @@ def get_array(self, scale_factor: float = None, dtype=numpy.dtype('uint8')) -> n
array: numpy.ndarray = self.data['img']

if scale_factor is None:
# Adjust brightness to average 18% grey
scale_factor = 255 * 0.18 / array.mean()
# Adjust brightness to target average exposure
scale_factor = maximum_value * mean_exposure / array.mean()

numpy.multiply(array, scale_factor, out=array, casting='unsafe')

Expand Down

0 comments on commit d79c0b7

Please sign in to comment.