6.4. tracer.color Submodule¶
6.4.1. tracer.color.tools¶
- optrace.tracer.color.tools.blackbody(wl, T=6504.0)¶
Get the spectral radiance of a planck blackbody curve. Unit is W/(sr m³).
- optrace.tracer.color.tools.normalized_blackbody(wl, T=6504.0)¶
Get the spectral power density of a planck blackbody curve. The values are normalized so that the highest value in the visible region, defined by global_options.wavelength_range is equal to 1.
6.4.2. tracer.color.illuminants¶
- optrace.tracer.color.illuminants.a_illuminant(wl)¶
A standard illuminant (CIE Colorimetry, 3. Edition, 2004). Typical, domestic, tungsten-filament lighting. Color temperature of 2856K.
- optrace.tracer.color.illuminants.c_illuminant(wl)¶
C standard illuminant (CIE Colorimetry, 3. Edition, 2004). Obsolete, average / north sky daylight. Color temperature of 6774K.
- optrace.tracer.color.illuminants.d50_illuminant(wl)¶
D50 standard illuminant (CIE Colorimetry, 3. Edition, 2004). Horizon light. Color temperature of 5003K.
- optrace.tracer.color.illuminants.d55_illuminant(wl)¶
D55 standard illuminant (CIE Colorimetry, 3. Edition, 2004). Mid-morning/mid-afternoon daylight. Color temperature of 5503K.
- optrace.tracer.color.illuminants.d65_illuminant(wl)¶
D65 standard illuminant (CIE Colorimetry, 3. Edition, 2004). Noon daylight. Color temperature of 6504K.
- optrace.tracer.color.illuminants.d75_illuminant(wl)¶
D75 standard illuminant (CIE Colorimetry, 3. Edition, 2004). North sky daylight. Color temperature of 7504K.
- optrace.tracer.color.illuminants.e_illuminant(wl)¶
E standard illuminant (CIE Colorimetry, 3. Edition, 2004). Equal energy radiator with a color temperature of 5455K.
- optrace.tracer.color.illuminants.f11_illuminant(wl)¶
F11 standard illuminant (CIE Colorimetry, 3. Edition, 2004). Narrowband triband fluorescent lamp in R, G, B regions. Color temperature of 4000K.
- optrace.tracer.color.illuminants.f2_illuminant(wl)¶
F2 standard illuminant (CIE Colorimetry, 3. Edition, 2004). Fluorescent lamp with two semi-broadband emissions. Color temperature of 4230K.
- optrace.tracer.color.illuminants.f7_illuminant(wl)¶
F7 standard illuminant (CIE Colorimetry, 3. Edition, 2004). Broadband fluorescent lamp with multiple phosphors. Color temperature of 6500K.
- optrace.tracer.color.illuminants.led_b1_illuminant(wl)¶
LED-B1 standard illuminant (CIE Colorimetry, 4th Edition, 2018) Blue excited phosphor type LED with a color temperature of 2733K.
- optrace.tracer.color.illuminants.led_b2_illuminant(wl)¶
LED-B2 standard illuminant (CIE Colorimetry, 4th Edition, 2018) Blue excited phosphor type LED with a color temperature of 2998K.
- optrace.tracer.color.illuminants.led_b3_illuminant(wl)¶
LED-B3 standard illuminant (CIE Colorimetry, 4th Edition, 2018) Blue excited phosphor type LED with a color temperature of 4103K.
- optrace.tracer.color.illuminants.led_b4_illuminant(wl)¶
LED-B4 standard illuminant (CIE Colorimetry, 4th Edition, 2018) Blue excited phosphor type LED with a color temperature of 5109K.
- optrace.tracer.color.illuminants.led_b5_illuminant(wl)¶
LED-B5 standard illuminant (CIE Colorimetry, 4th Edition, 2018) Blue excited phosphor type LED with a color temperature of 6598K.
- optrace.tracer.color.illuminants.led_bh1_illuminant(wl)¶
LED-BH1 standard illuminant (CIE Colorimetry, 4th Edition, 2018) Hybrid type white LED with added red. Color temperature of 2851K.
- optrace.tracer.color.illuminants.led_rgb1_illuminant(wl)¶
LED-RGB1 standard illuminant (CIE Colorimetry, 4th Edition, 2018) Tri-led RGB source with a color temperature of 2840K.
- optrace.tracer.color.illuminants.led_v1_illuminant(wl)¶
LED-V1 standard illuminant (CIE Colorimetry, 4th Edition, 2018) Violet enhanced blue excited phosphor LED with a color temperature of 2724K.
6.4.3. tracer.color.observers¶
- optrace.tracer.color.observers.x_observer(wl)¶
CIE 1931 2° colorimetric standard observer x.
- optrace.tracer.color.observers.y_observer(wl)¶
CIE 1931 2° colorimetric standard observer y.
6.4.4. tracer.color.xyz¶
- optrace.tracer.color.xyz.complementary_wavelength(XYZ_s, res=10000)¶
Calculate the complementary wavelength for a given XYZ color coordinate and the D65 whitepoint.
- optrace.tracer.color.xyz.dominant_wavelength(XYZ_s, res=10000)¶
Calculate the dominant wavelength for a given XYZ color coordinate and the D65 whitepoint.
- optrace.tracer.color.xyz.xyY_to_xyz(xyy)¶
Convert xyY to XYZ colorspace values.
- optrace.tracer.color.xyz.xyz_from_spectrum(wl, spec, method='sum')¶
Calculate the tristimulus values XYZ from a spectral distribution.
- Parameters:
wl – 1D wavelength vector
spec – 1D spectral value vector, same shape as wl parameter
method – “sum” or “trapz”, method for numerical integration
- Returns:
numpy array of 3 elements
- Return type:
- optrace.tracer.color.xyz.xyz_to_xyY(xyz)¶
Convert XYZ to xyY coordinates. Black gets mapped to the whitepoint and Y=0
6.4.5. tracer.color.srgb¶
- optrace.tracer.color.srgb.gauss(x, mu, sig)¶
Gauss Function / Normal distribution. Normalized so peak value is 1.
- optrace.tracer.color.srgb.get_chroma_scale(Luv, L_th=0.0)¶
Calculate the chroma scaling factor for xyz_to_srgb_linear with mode “Perceptual” Ignore values below L_th*np.max(L) with L being the lightness. Impossible colors are also ignored.
This functions determines the needed scaling factor so all image colors are inside the sRGB gamut.
- Parameters:
Luv (ndarray) – CIELUV image values (shape (Ny, Nx, 3))
L_th – optional lightness threshold as fraction of the peak lightness (range 0 - 1)
- Returns:
saturation scaling factor (0-1)
- optrace.tracer.color.srgb.log_srgb(img)¶
Logarithmically scale sRGB values. This is done by rescaling the lightness of the colors (in CIELUV) while keeping the chromaticities the same.
- optrace.tracer.color.srgb.outside_srgb_gamut(xyz)¶
Checks if the XYZ colors produce valid colors inside the sRGB gamut
- optrace.tracer.color.srgb.power_from_srgb_linear(rgbl)¶
Get a measure of pixel power/probability with the sRGB primaries above.
- optrace.tracer.color.srgb.random_wavelengths_from_srgb(rgb)¶
Choose random wavelengths from sRGB colors.
- optrace.tracer.color.srgb.spectral_colormap(wl)¶
Get a spectral colormap in sRGB for wavelength values. The Hue is rendered physically correct, however the lightness and saturation are set to be visually pleasing
- optrace.tracer.color.srgb.srgb_b_primary(wl)¶
Exemplary sRGB b primary curve.
- optrace.tracer.color.srgb.srgb_g_primary(wl)¶
Exemplary sRGB g primary curve.
- optrace.tracer.color.srgb.srgb_linear_to_srgb(rgbl)¶
Conversion linear RGB to sRGB. Values should be inside range [0, 1], however this is not enforced. For negative values srgb(-a) is the same as -srgb(a)
- optrace.tracer.color.srgb.srgb_linear_to_xyz(rgbl)¶
Conversion from linear sRGB values to XYZ
- optrace.tracer.color.srgb.srgb_r_primary(wl)¶
Exemplary sRGB r primary curve.
- optrace.tracer.color.srgb.srgb_to_srgb_linear(rgb)¶
Conversion from sRGB to linear RGB values. sRGB values should be inside range [0, 1], however this is not checked or enforced. For negative values -a srgb_to_srgb_linear(-a) is the same as -srgb_to_srgb_linear(a)
- optrace.tracer.color.srgb.srgb_to_xyz(rgb)¶
Conversion from sRGB to XYZ.
- optrace.tracer.color.srgb.xyz_to_srgb(xyz, normalize=True, clip=True, rendering_intent='Absolute', L_th=0, chroma_scale=None)¶
Conversion of XYZ to sRGB Linear to sRGB.
see function :srgb_linear_to_srgb() for detail on rendering intents.
- Parameters:
xyz (ndarray) – XYZ image (numpy 3D array, XYZ channels in third dimension)
normalize (bool) – if values are normalized before conversion (bool)
rendering_intent (str) – one of SRGB_RENDERING_INTENTS (“Ignore”, “Absolute”, “Perceptual”)
clip (bool) – if sRGB values are clipped before gamma correction
L_th (float) – lightness threshold for mode “Perceptual”.
chroma_scale (float) – chroma_scale option for mode “sRGB (Perceptual RI)”
- Returns:
sRGB image (numpy 3D array)
- Return type:
- optrace.tracer.color.srgb.xyz_to_srgb_linear(xyz, normalize=True, rendering_intent='Absolute', L_th=0.0, chroma_scale=None)¶
Conversion XYZ to linear RGB values.
Ignore: Leave out of gamut colors as is Absolute: Clip the saturation of out-of-bound colors, but preserve hue and brightness
Perceptual: Scale the chroma of all pixels so saturation ratios stay the same. Scaling factor is determined so all colors are representable. Additional lightness L_th threshold: L_th = 0.01 ignores all colors below 1% of the peak brightness for saturation detection. Prevents dark, merely visible pixels from scaling down the saturation of the whole image. Impossible colors are left untouched by this mode, so clipping the output values is recommended. Alternatively the chroma_scale parameter can be provided that scales the chroma down by a fixed amount. The colors still outside the gamut after the operation are chroma clipped like in Absolute RI. So Perceptual RI with L_th or chroma_scale can be seen as hybrid method, perceptual for colors meeting the criteria, Absolute RI for colors not doing so.
- Parameters:
xyz (ndarray) – XYZ image (shape (Ny, Nx, 3))
normalize (bool) – if image is normalized to highest value before conversion (bool)
rendering_intent (str) – “Absolute”, “Perceptual” or “Ignore”, see above
L_th (float) – lightness threshold for mode “Perceptual”.
chroma_scale (float) – chroma_scale option for mode “Perceptual”
- Returns:
linear sRGB image (shape (Ny, Nx, 3))
- Return type:
- optrace.tracer.color.srgb.SRGB_B_XY: list[float, float] = [0.15, 0.06]¶
sRGB blue primary in xy coordinates
- optrace.tracer.color.srgb.SRGB_G_XY: list[float, float] = [0.3, 0.6]¶
sRGB green primary in xy coordinates
6.4.6. tracer.color.luv¶
- optrace.tracer.color.luv.luv_chroma(luv)¶
Get Chroma from CIELUV values. Calculation using https://en.wikipedia.org/wiki/Colorfulness#Chroma
- optrace.tracer.color.luv.luv_hue(luv)¶
Get Hue from CIELUV values. Calculation using https://en.wikipedia.org/wiki/Colorfulness#Chroma
- optrace.tracer.color.luv.luv_saturation(luv)¶
Get Chroma from CIELUV values. Calculation using https://en.wikipedia.org/wiki/Colorfulness#Saturation
- optrace.tracer.color.luv.luv_to_u_v_l(luv)¶
Convert to CIE 1976 LUV to chromaticity color space u’v’L (uniform chromaticity scale diagram coordinates)
- optrace.tracer.color.luv.luv_to_xyz(luv)¶
Convert CIE 1976 LUV back to XYZ.
- optrace.tracer.color.luv.xyz_to_luv(xyz, normalize=True)¶
Convert XYZ values to CIE 1976 LUV colorspace.
- optrace.tracer.color.luv.SRGB_B_UV: list[float, float] = [0.1754385965, 0.1578947368]¶
sRGBgblue primary in u’v’ coordinates
- optrace.tracer.color.luv.SRGB_G_UV: list[float, float] = [0.125, 0.5625]¶
sRGB green primary in u’v’ coordinates
- optrace.tracer.color.luv.SRGB_R_UV: list[float, float] = [0.4507042254, 0.5228873239]¶
sRGB red primary in u’v’ coordinates