From fbe4b275653ce7c10f921d6b9f0fb09961dba542 Mon Sep 17 00:00:00 2001 From: Joe Heffer Date: Mon, 17 Jun 2024 12:21:03 +0100 Subject: [PATCH] feat: auto expose each image to 18% grey --- backend/btviewer/blueprints/photo/model.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/backend/btviewer/blueprints/photo/model.py b/backend/btviewer/blueprints/photo/model.py index 5306d9c..330266b 100644 --- a/backend/btviewer/blueprints/photo/model.py +++ b/backend/btviewer/blueprints/photo/model.py @@ -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. @@ -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)