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 8be22b1 commit fbe4b27
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions backend/btviewer/blueprints/photo/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ def data(self) -> Mapping:
return self.load()

@property
def array(self, scale_factor: float = None, dtype=numpy.dtype('uint8')) -> numpy.array:
def array(self):
return self.get_array()

def get_array(self, scale_factor: float = None, dtype=numpy.dtype('uint8')) -> numpy.array:
"""
2D image data array of pixel values.
Expand All @@ -163,10 +166,10 @@ def array(self, scale_factor: float = None, dtype=numpy.dtype('uint8')) -> numpy
# Load image data
array: numpy.ndarray = self.data['img']

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

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

return array.astype(dtype=dtype)
Expand Down

0 comments on commit fbe4b27

Please sign in to comment.