Utils
utils
Additional utility functions.
Functions:
-
apply_lut_tetrahedral_int–Apply a 3D LUT using tetrahedral interpolation.
-
apply_lut_tetrahedral_int_cuda–CUDA kernel: Apply a 3D LUT with tetrahedral interpolation.
-
apply_per_pixel–Convert a 3D (H, W, 3) or 4D (N, H, W, 3) RGB array to HSV.
-
construct_spectral_density–Split single density curve into separate layers using local extrema.
-
create_lut–Creates a cube LUT from using
.film_spectral.FilmSpectral.generate_conversion. -
generate_all_summing_to_one–Generate all (a, b, c) such that a + b + c = 1 and a, b, c ∈ [0, 1]
-
multi_channel_interp–Resamples each (xp, fp) pair to a uniform grid for fast lookup.
-
plot_chromaticity–Plot a chromaticity value.
-
plot_chromaticties–Plot a chromaticity values.
-
plot_gamut–Plots the gamut of a CST matrix.
-
plot_gamuts–Plots the gamut of CST matrices.
-
run_lut_cuda–Wrapper: runs the CUDA kernel on an image + LUT.
-
uniform_multi_channel_interp–Interpolate values in an N-D array over the last dimension.
-
wavelength_argmax–Gets the argmax of a spectral distribution.
-
wavelength_argmin–Gets the argmax of a spectral distribution.
Attributes:
-
CUDA_AVAILABLE–Whether cuda is available through cupy.
CUDA_AVAILABLE
module-attribute
CUDA_AVAILABLE = True
Whether cuda is available through cupy.
apply_lut_tetrahedral_int
Apply a 3D LUT using tetrahedral interpolation.
The input image is expected to have dtype uint16 with values in
the range [0, 65535]. The output image has dtype uint8 with
values in the range [0, 255].
Parameters:
-
(imagendarray) –Input image of shape
(H, W, 3), dtypeuint16. -
–lut3D lookup table of shape
(size, size, size, 3), dtypeuint8.
Returns:
-
ndarray–Output image of shape
(H, W, 3), dtypeuint8.
apply_lut_tetrahedral_int_cuda
apply_lut_tetrahedral_int_cuda(image, lut, out, size, scale, scale_out)
CUDA kernel: Apply a 3D LUT with tetrahedral interpolation. Input : uint16 image in [0, 65535] Output: uint8 image in [0, 255]
apply_per_pixel
apply_per_pixel(rgb, function)
Convert a 3D (H, W, 3) or 4D (N, H, W, 3) RGB array to HSV. RGB values are expected in range [0, 1]. Returns array of same shape with HSV values.
H in [0, 1], S in [0, 1], V in [0, 1].
construct_spectral_density
construct_spectral_density(ref_density: SpectralDistribution, sigma=25) -> ndarray
Split single density curve into separate layers using local extrema.
create_lut
create_lut(
negative_film,
print_film=None,
lut_size=33,
name="test",
cube=True,
verbose=False,
**kwargs,
)
Creates a cube LUT from using .film_spectral.FilmSpectral.generate_conversion.
generate_all_summing_to_one
generate_all_summing_to_one(steps)
Generate all (a, b, c) such that a + b + c = 1 and a, b, c ∈ [0, 1] with a specified number of steps (granularity).
Parameters:
-
(stepsint) –The number of divisions of the interval [0, 1].
Returns:
-
–
np.ndarray: Array of shape (n, 3) with all combinations summing to 1.
multi_channel_interp
multi_channel_interp(
x,
xps,
fps,
num_bins=1024,
interpolate=False,
left_extrapolate=False,
right_extrapolate=False,
)
Resamples each (xp, fp) pair to a uniform grid for fast lookup.
Returns:
-
xp_common–np.ndarray, shape (num_bins,)
-
fp_uniform–np.ndarray, shape (n_channels, num_bins)
plot_chromaticity
plot_chromaticity(chromaticity, label=None)
Plot a chromaticity value.
plot_chromaticties
plot_chromaticties(chromaticies, labels=None)
Plot a chromaticity values.
plot_gamut
plot_gamut(rgb_to_xyz: ndarray, label=None)
Plots the gamut of a CST matrix.
run_lut_cuda
run_lut_cuda(image: ndarray, lut: ndarray, exponent=16, out_exponent=8) -> ndarray
Wrapper: runs the CUDA kernel on an image + LUT.
uniform_multi_channel_interp
uniform_multi_channel_interp(
x: ndarray,
xp_common: ndarray,
fp_uniform: ndarray,
interpolate=True,
left_extrapolate=False,
right_extrapolate=False,
) -> ndarray
Interpolate values in an N-D array over the last dimension.
Interpolates values in an N-dimensional array x across the last
dimension (channels) using a precomputed uniform grid defined by
xp_common and fp_uniform. Optionally performs linear
interpolation or nearest-neighbor selection, and supports linear
extrapolation on either end of the grid.
Parameters:
-
–xInput array of shape
(..., channels). -
(xp_commonndarray) –Monotonically increasing 1D array of shape
(num_bins,)representing the shared grid points. -
(fp_uniformndarray) –Array of shape
(channels, num_bins)containing function values at each grid point for every channel. -
–interpolateIf
True, perform linear interpolation. IfFalse, use nearest-neighbor selection. -
–left_extrapolateIf
True, apply linear extrapolation for values less thanxp_common[0]. -
–right_extrapolateIf
True, apply linear extrapolation for values greater thanxp_common[-1].
Returns:
-
ndarray–Interpolated array with the same shape as
x.
wavelength_argmax
wavelength_argmax(distribution: SpectralDistribution, low=None, high=None) -> int
Gets the argmax of a spectral distribution.
wavelength_argmin
wavelength_argmin(distribution: SpectralDistribution, low=None, high=None) -> int
Gets the argmax of a spectral distribution.