From a80f42ec5d53d4e08dd2e24be106dba55241c74c Mon Sep 17 00:00:00 2001 From: Askaniy Date: Mon, 14 Oct 2024 23:24:19 +0300 Subject: [PATCH] Bug fixing. sRGB for images --- src/auxiliary.py | 4 ++-- src/core.py | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/auxiliary.py b/src/auxiliary.py index d91077d..c678709 100644 --- a/src/auxiliary.py +++ b/src/auxiliary.py @@ -208,7 +208,7 @@ def extrapolating(x: np.ndarray, y: np.ndarray, x_arr: np.ndarray, step: int|flo if x[0] > x_arr[0]: # Extrapolation to blue x1 = np.arange(x_arr[0], x[0], step) - if np.all(y[0]) == 0: + if np.all(y[0] == 0): # Corner point is zero -> no extrapolation needed: most likely it's a filter profile y1 = np.zeros((x1.size, *obj_shape)) else: @@ -227,7 +227,7 @@ def extrapolating(x: np.ndarray, y: np.ndarray, x_arr: np.ndarray, step: int|flo if x[-1] < x_arr[-1]: # Extrapolation to red x1 = np.arange(x[-1], x_arr[-1], step) + step - if np.all(y[0]) == 0: + if np.all(y[0] == 0): # Corner point is zero -> no extrapolation needed: most likely it's a filter profile y1 = np.zeros((x1.size, *obj_shape)) else: diff --git a/src/core.py b/src/core.py index 2a38693..a74e1c0 100644 --- a/src/core.py +++ b/src/core.py @@ -447,7 +447,7 @@ def __rmatmul__(self, other): operand1 = other.define_on_range(self.nm, crop=True) operand2 = self else: - # Why Spectrum/FilterSystem needs extrapolation? + # Why Spectrum/FilterSystem needs extrapolation too? # For the cases of bolometric albedo operations such as `Sun @ Mercury`. operand1 = other.define_on_range(self.nm, crop=False) operand2 = self.define_on_range(other.nm, crop=False) @@ -1302,7 +1302,8 @@ def from_spectral_data(cls, data: _TrueColorToolsObject, maximize_brightness=Fal """ Convolves the (photo)spectral object with one of the available CMF systems """ if srgb: xyz = (data @ xyz_cmf).br / 3 # why? don't know, it works - rgb = srgb_system.T.dot(xyz) + #rgb = srgb_system.T.dot(xyz) + rgb = np.tensordot(srgb_system.T, xyz, axes=(1, 0)) if np.any(rgb < 0): print(f'# Note for the Color object "{data.name}"') print(f'- RGB derived from XYZ turned out to be outside the color space: rgb={rgb}') @@ -1323,7 +1324,7 @@ def grayscale(self): # inaccurate CIE standard usage (TODO) return np.dot(self.br, (0.2126, 0.7152, 0.0722)) - def __matmul__(self, other): + def __mul__(self, other): """ Creates a new ColorObject with adjusted brightness """ if isinstance(other, int|float): output = deepcopy(self)