Skip to content

Commit

Permalink
Bug fixing. sRGB for images
Browse files Browse the repository at this point in the history
  • Loading branch information
Askaniy committed Oct 14, 2024
1 parent 42c32ba commit a80f42e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/auxiliary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions src/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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}')
Expand All @@ -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)
Expand Down

0 comments on commit a80f42e

Please sign in to comment.