Skip to content

Commit

Permalink
Use np.resize in colour.uv_to_Luv, colour.UCS_to_uv and `colour…
Browse files Browse the repository at this point in the history
….xy_to_xyY` definitions.
  • Loading branch information
KelSolaar committed May 13, 2024
1 parent 76579ee commit 400ecb9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
7 changes: 4 additions & 3 deletions colour/models/cie_luv.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

from __future__ import annotations

import numpy as np

from colour.algebra import sdiv, sdiv_mode
from colour.colorimetry import (
CCS_ILLUMINANTS,
Expand All @@ -42,7 +44,6 @@
domain_range_scale,
from_range_1,
from_range_100,
full,
to_domain_1,
to_domain_100,
tsplit,
Expand Down Expand Up @@ -290,7 +291,7 @@ def uv_to_Luv(
illuminant: ArrayLike = CCS_ILLUMINANTS["CIE 1931 2 Degree Standard Observer"][
"D65"
],
L: float = 100,
L: NDArrayFloat = 100,
) -> NDArrayFloat:
"""
Return the *CIE L\\*u\\*v\\** colourspace array from given :math:`uv^p`
Expand Down Expand Up @@ -351,7 +352,7 @@ def uv_to_Luv(
X = sdiv(9 * Y * u, 4 * v)
Z = sdiv(Y * (-3 * u - 20 * v + 12), 4 * v)

XYZ = tstack([X, full(u.shape, Y), Z])
XYZ = tstack([X, np.resize(Y, u.shape), Z])

return XYZ_to_Luv(from_range_1(XYZ), illuminant)

Expand Down
7 changes: 4 additions & 3 deletions colour/models/cie_ucs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@

from __future__ import annotations

import numpy as np

from colour.algebra import sdiv, sdiv_mode
from colour.hints import ArrayLike, NDArrayFloat
from colour.utilities import (
as_float_scalar,
from_range_1,
full,
to_domain_1,
tsplit,
tstack,
Expand Down Expand Up @@ -189,7 +190,7 @@ def UCS_to_uv(UVW: ArrayLike) -> NDArrayFloat:
return uv


def uv_to_UCS(uv: ArrayLike, V: float = 1) -> NDArrayFloat:
def uv_to_UCS(uv: ArrayLike, V: NDArrayFloat = 1) -> NDArrayFloat:
"""
Return the *CIE 1960 UCS* colourspace array from given *uv* chromaticity
coordinates.
Expand Down Expand Up @@ -224,7 +225,7 @@ def uv_to_UCS(uv: ArrayLike, V: float = 1) -> NDArrayFloat:
V = as_float_scalar(to_domain_1(V))

with sdiv_mode():
UVW = tstack([V * sdiv(u, v), full(u.shape, V), -V * sdiv(u + v - 1, v)])
UVW = tstack([V * sdiv(u, v), np.resize(V, u.shape), -V * sdiv(u + v - 1, v)])

return from_range_1(UVW)

Expand Down
5 changes: 2 additions & 3 deletions colour/models/cie_xyy.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
as_float_array,
as_float_scalar,
from_range_1,
full,
to_domain_1,
tsplit,
tstack,
Expand Down Expand Up @@ -221,7 +220,7 @@ def xyY_to_xy(xyY: ArrayLike) -> NDArrayFloat:
return xy


def xy_to_xyY(xy: ArrayLike, Y: float = 1) -> NDArrayFloat:
def xy_to_xyY(xy: ArrayLike, Y: NDArrayFloat = 1) -> NDArrayFloat:
"""
Convert from *CIE xy* chromaticity coordinates to *CIE xyY* colourspace by
extending the array last dimension with given :math:`Y` *luminance*.
Expand Down Expand Up @@ -289,7 +288,7 @@ def xy_to_xyY(xy: ArrayLike, Y: float = 1) -> NDArrayFloat:

x, y = tsplit(xy)

xyY = tstack([x, y, full(x.shape, Y)])
xyY = tstack([x, y, np.resize(Y, x.shape)])

return from_range_1(xyY, np.array([1, 1, 100]))

Expand Down

0 comments on commit 400ecb9

Please sign in to comment.