Skip to content

Commit

Permalink
Merge branch 'feature/v0.4.5' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
KelSolaar committed Jun 1, 2024
2 parents efb651e + 80fce67 commit 8e965cf
Show file tree
Hide file tree
Showing 38 changed files with 193 additions and 304 deletions.
6 changes: 3 additions & 3 deletions colour/adaptation/cie1994.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import numpy as np

from colour.adaptation import CAT_VON_KRIES
from colour.algebra import sdiv, sdiv_mode, spow, vector_dot
from colour.algebra import sdiv, sdiv_mode, spow, vecmul
from colour.hints import ArrayLike, NDArrayFloat
from colour.utilities import (
as_float_array,
Expand Down Expand Up @@ -188,7 +188,7 @@ def XYZ_to_RGB_CIE1994(XYZ: ArrayLike) -> NDArrayFloat:
array([ 25.8244273..., 18.6791422..., 4.8390194...])
"""

return vector_dot(MATRIX_XYZ_TO_RGB_CIE1994, XYZ)
return vecmul(MATRIX_XYZ_TO_RGB_CIE1994, XYZ)


def RGB_to_XYZ_CIE1994(RGB: ArrayLike) -> NDArrayFloat:
Expand All @@ -212,7 +212,7 @@ def RGB_to_XYZ_CIE1994(RGB: ArrayLike) -> NDArrayFloat:
array([ 28. , 21.26, 5.27])
"""

return vector_dot(MATRIX_RGB_TO_XYZ_CIE1994, RGB)
return vecmul(MATRIX_RGB_TO_XYZ_CIE1994, RGB)


def intermediate_values(xy_o: ArrayLike) -> NDArrayFloat:
Expand Down
18 changes: 9 additions & 9 deletions colour/adaptation/cmccat2000.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import numpy as np

from colour.adaptation import CAT_CMCCAT2000
from colour.algebra import vector_dot
from colour.algebra import vecmul
from colour.hints import ArrayLike, Literal, NDArrayFloat
from colour.utilities import (
CanonicalMapping,
Expand Down Expand Up @@ -168,9 +168,9 @@ def chromatic_adaptation_forward_CMCCAT2000(
L_A1 = as_float_array(L_A1)
L_A2 = as_float_array(L_A2)

RGB = vector_dot(CAT_CMCCAT2000, XYZ)
RGB_w = vector_dot(CAT_CMCCAT2000, XYZ_w)
RGB_wr = vector_dot(CAT_CMCCAT2000, XYZ_wr)
RGB = vecmul(CAT_CMCCAT2000, XYZ)
RGB_w = vecmul(CAT_CMCCAT2000, XYZ_w)
RGB_wr = vecmul(CAT_CMCCAT2000, XYZ_wr)

D = surround.F * (
0.08 * np.log10(0.5 * (L_A1 + L_A2))
Expand All @@ -182,7 +182,7 @@ def chromatic_adaptation_forward_CMCCAT2000(
a = D * XYZ_w[..., 1] / XYZ_wr[..., 1]

RGB_c = RGB * (a[..., None] * (RGB_wr / RGB_w) + 1 - D[..., None])
XYZ_c = vector_dot(CAT_INVERSE_CMCCAT2000, RGB_c)
XYZ_c = vecmul(CAT_INVERSE_CMCCAT2000, RGB_c)

return from_range_100(XYZ_c)

Expand Down Expand Up @@ -261,9 +261,9 @@ def chromatic_adaptation_inverse_CMCCAT2000(
L_A1 = as_float_array(L_A1)
L_A2 = as_float_array(L_A2)

RGB_c = vector_dot(CAT_CMCCAT2000, XYZ_c)
RGB_w = vector_dot(CAT_CMCCAT2000, XYZ_w)
RGB_wr = vector_dot(CAT_CMCCAT2000, XYZ_wr)
RGB_c = vecmul(CAT_CMCCAT2000, XYZ_c)
RGB_w = vecmul(CAT_CMCCAT2000, XYZ_w)
RGB_wr = vecmul(CAT_CMCCAT2000, XYZ_wr)

D = surround.F * (
0.08 * np.log10(0.5 * (L_A1 + L_A2))
Expand All @@ -275,7 +275,7 @@ def chromatic_adaptation_inverse_CMCCAT2000(
a = D * XYZ_w[..., 1] / XYZ_wr[..., 1]

RGB = RGB_c / (a[..., None] * (RGB_wr / RGB_w) + 1 - D[..., None])
XYZ = vector_dot(CAT_INVERSE_CMCCAT2000, RGB)
XYZ = vecmul(CAT_INVERSE_CMCCAT2000, RGB)

return from_range_100(XYZ)

Expand Down
24 changes: 12 additions & 12 deletions colour/adaptation/fairchild1990.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import numpy as np

from colour.adaptation import CAT_VON_KRIES
from colour.algebra import sdiv, sdiv_mode, spow, vector_dot
from colour.algebra import sdiv, sdiv_mode, spow, vecmul
from colour.hints import ArrayLike, NDArrayFloat
from colour.utilities import (
as_float_array,
Expand Down Expand Up @@ -129,9 +129,9 @@ def chromatic_adaptation_Fairchild1990(
XYZ_r = to_domain_100(XYZ_r)
Y_n = as_float_array(Y_n)

LMS_1 = vector_dot(MATRIX_XYZ_TO_RGB_FAIRCHILD1990, XYZ_1)
LMS_n = vector_dot(MATRIX_XYZ_TO_RGB_FAIRCHILD1990, XYZ_n)
LMS_r = vector_dot(MATRIX_XYZ_TO_RGB_FAIRCHILD1990, XYZ_r)
LMS_1 = vecmul(MATRIX_XYZ_TO_RGB_FAIRCHILD1990, XYZ_1)
LMS_n = vecmul(MATRIX_XYZ_TO_RGB_FAIRCHILD1990, XYZ_n)
LMS_r = vecmul(MATRIX_XYZ_TO_RGB_FAIRCHILD1990, XYZ_r)

p_LMS = degrees_of_adaptation(LMS_1, Y_n, discount_illuminant=discount_illuminant)

Expand All @@ -141,16 +141,16 @@ def chromatic_adaptation_Fairchild1990(
A_1 = row_as_diagonal(a_LMS_1)
A_2 = row_as_diagonal(a_LMS_2)

LMSp_1 = vector_dot(A_1, LMS_1)
LMSp_1 = vecmul(A_1, LMS_1)

c = 0.219 - 0.0784 * np.log10(Y_n)
C = row_as_diagonal(tstack([c, c, c]))

LMS_a = vector_dot(C, LMSp_1)
LMSp_2 = vector_dot(np.linalg.inv(C), LMS_a)
LMS_a = vecmul(C, LMSp_1)
LMSp_2 = vecmul(np.linalg.inv(C), LMS_a)

LMS_c = vector_dot(np.linalg.inv(A_2), LMSp_2)
XYZ_c = vector_dot(MATRIX_RGB_TO_XYZ_FAIRCHILD1990, LMS_c)
LMS_c = vecmul(np.linalg.inv(A_2), LMSp_2)
XYZ_c = vecmul(MATRIX_RGB_TO_XYZ_FAIRCHILD1990, LMS_c)

return from_range_100(XYZ_c)

Expand All @@ -176,7 +176,7 @@ def XYZ_to_RGB_Fairchild1990(XYZ: ArrayLike) -> NDArrayFloat:
array([ 22.1231935..., 23.6054224..., 22.9279534...])
"""

return vector_dot(MATRIX_XYZ_TO_RGB_FAIRCHILD1990, XYZ)
return vecmul(MATRIX_XYZ_TO_RGB_FAIRCHILD1990, XYZ)


def RGB_to_XYZ_Fairchild1990(RGB: ArrayLike) -> NDArrayFloat:
Expand All @@ -200,7 +200,7 @@ def RGB_to_XYZ_Fairchild1990(RGB: ArrayLike) -> NDArrayFloat:
array([ 19.53, 23.07, 24.97])
"""

return vector_dot(MATRIX_RGB_TO_XYZ_FAIRCHILD1990, RGB)
return vecmul(MATRIX_RGB_TO_XYZ_FAIRCHILD1990, RGB)


def degrees_of_adaptation(
Expand Down Expand Up @@ -247,7 +247,7 @@ def degrees_of_adaptation(
v = as_float_array(v)

# E illuminant.
LMS_E = vector_dot(CAT_VON_KRIES, ones(LMS.shape))
LMS_E = vecmul(CAT_VON_KRIES, ones(LMS.shape))

Ye_n = spow(Y_n, v)

Expand Down
14 changes: 7 additions & 7 deletions colour/adaptation/fairchild2020.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import numpy as np

from colour.adaptation import CHROMATIC_ADAPTATION_TRANSFORMS
from colour.algebra import matrix_dot, sdiv, sdiv_mode, vector_dot
from colour.algebra import sdiv, sdiv_mode, vecmul
from colour.hints import ArrayLike, Literal, NDArrayFloat
from colour.utilities import (
CanonicalMapping,
Expand Down Expand Up @@ -202,15 +202,15 @@ def matrix_chromatic_adaptation_vk20(

D_n, D_r, D_p = coefficients

LMS_n = vector_dot(M, XYZ_n)
LMS_r = vector_dot(M, XYZ_r)
LMS_p = vector_dot(M, XYZ_p)
LMS_n = vecmul(M, XYZ_n)
LMS_r = vecmul(M, XYZ_r)
LMS_p = vecmul(M, XYZ_p)

with sdiv_mode():
D = row_as_diagonal(sdiv(1, (D_n * LMS_n + D_r * LMS_r + D_p * LMS_p)))

M_CAT = matrix_dot(np.linalg.inv(M), D)
M_CAT = matrix_dot(M_CAT, M)
M_CAT = np.matmul(np.linalg.inv(M), D)
M_CAT = np.matmul(M_CAT, M)

return M_CAT

Expand Down Expand Up @@ -316,6 +316,6 @@ def chromatic_adaptation_vK20(
M_CAT = matrix_chromatic_adaptation_vk20(
XYZ_p, XYZ_n, XYZ_r, transform, coefficients
)
XYZ_a = vector_dot(M_CAT, XYZ)
XYZ_a = vecmul(M_CAT, XYZ)

return from_range_1(XYZ_a)
12 changes: 6 additions & 6 deletions colour/adaptation/vonkries.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import numpy as np

from colour.adaptation import CHROMATIC_ADAPTATION_TRANSFORMS
from colour.algebra import matrix_dot, sdiv, sdiv_mode, vector_dot
from colour.algebra import sdiv, sdiv_mode, vecmul
from colour.hints import (
ArrayLike,
LiteralChromaticAdaptationTransform,
Expand Down Expand Up @@ -117,16 +117,16 @@ def matrix_chromatic_adaptation_VonKries(

M = CHROMATIC_ADAPTATION_TRANSFORMS[transform]

RGB_w = vector_dot(M, XYZ_w)
RGB_wr = vector_dot(M, XYZ_wr)
RGB_w = vecmul(M, XYZ_w)
RGB_wr = vecmul(M, XYZ_wr)

with sdiv_mode():
D = sdiv(RGB_wr, RGB_w)

D = row_as_diagonal(D)

M_CAT = matrix_dot(np.linalg.inv(M), D)
M_CAT = matrix_dot(M_CAT, M)
M_CAT = np.matmul(np.linalg.inv(M), D)
M_CAT = np.matmul(M_CAT, M)

return M_CAT

Expand Down Expand Up @@ -202,6 +202,6 @@ def chromatic_adaptation_VonKries(
XYZ = to_domain_1(XYZ)

M_CAT = matrix_chromatic_adaptation_VonKries(XYZ_w, XYZ_wr, transform)
XYZ_a = vector_dot(M_CAT, XYZ)
XYZ_a = vecmul(M_CAT, XYZ)

return from_range_1(XYZ_a)
12 changes: 6 additions & 6 deletions colour/adaptation/zhai2018.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import numpy as np

from colour.adaptation import CHROMATIC_ADAPTATION_TRANSFORMS
from colour.algebra import vector_dot
from colour.algebra import vecmul
from colour.hints import ArrayLike, Literal, NDArrayFloat, Union
from colour.utilities import (
as_float_array,
Expand Down Expand Up @@ -152,10 +152,10 @@ def chromatic_adaptation_Zhai2018(
transform = validate_method(transform, ("CAT02", "CAT16"))
M = CHROMATIC_ADAPTATION_TRANSFORMS[transform]

RGB_b = vector_dot(M, XYZ_b)
RGB_wb = vector_dot(M, XYZ_wb)
RGB_wd = vector_dot(M, XYZ_wd)
RGB_wo = vector_dot(M, XYZ_wo)
RGB_b = vecmul(M, XYZ_b)
RGB_wb = vecmul(M, XYZ_wb)
RGB_wd = vecmul(M, XYZ_wd)
RGB_wo = vecmul(M, XYZ_wo)

D_RGB_b = D_b * (Y_wb / Y_wo) * (RGB_wo / RGB_wb) + 1 - D_b
D_RGB_d = D_d * (Y_wd / Y_wo) * (RGB_wo / RGB_wd) + 1 - D_d
Expand All @@ -164,6 +164,6 @@ def chromatic_adaptation_Zhai2018(

RGB_d = D_RGB * RGB_b

XYZ_d = vector_dot(np.linalg.inv(M), RGB_d)
XYZ_d = vecmul(np.linalg.inv(M), RGB_d)

return from_range_100(XYZ_d)
14 changes: 10 additions & 4 deletions colour/algebra/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
spow,
normalise_vector,
normalise_maximum,
vector_dot,
matrix_dot,
vecmul,
euclidean_distance,
manhattan_distance,
linear_conversion,
Expand Down Expand Up @@ -65,8 +64,7 @@
"spow",
"normalise_vector",
"normalise_maximum",
"vector_dot",
"matrix_dot",
"vecmul",
"euclidean_distance",
"manhattan_distance",
"linear_conversion",
Expand Down Expand Up @@ -163,6 +161,14 @@ def __getattr__(self, attribute) -> Any:
}
"""Defines the *colour.algebra* sub-package API changes."""

# v0.4.5
API_CHANGES["ObjectRenamed"] = [
[
"colour.algebra.vector_dot",
"colour.algebra.vecmul",
],
]

if not is_documentation_building():
sys.modules["colour.algebra"] = algebra( # pyright: ignore
sys.modules["colour.algebra"], build_API_changes(API_CHANGES)
Expand Down
Loading

0 comments on commit 8e965cf

Please sign in to comment.