Last active
February 19, 2023 18:32
-
-
Save KelSolaar/b93bac6fa8022677dc26905006b52151 to your computer and use it in GitHub Desktop.
RGB Colourspaces - Planckian Locus CIE 1931 Chromaticity Diagram Plot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pylab | |
import colour | |
from colour.plotting import * | |
def RGB_colourspaces_planckian_locus_CIE_1931_chromaticity_diagram_plot( | |
colourspaces=None, cmfs='CIE 1931 2 Degree Standard Observer', | |
**kwargs): | |
settings = {'figure_size': (DEFAULT_FIGURE_WIDTH, DEFAULT_FIGURE_WIDTH)} | |
settings.update(kwargs) | |
canvas(**settings) | |
if colourspaces is None: | |
colourspaces = ('ITU-R BT.709', 'ACEScg', 'S-Gamut', 'Pointer Gamut') | |
cmfs, name = get_cmfs(cmfs), cmfs | |
settings = { | |
'title': | |
'{0} - {1} - CIE 1931 Chromaticity Diagram'.format( | |
', '.join(colourspaces), name), | |
'standalone': | |
False | |
} | |
settings.update(kwargs) | |
planckian_locus_CIE_1931_chromaticity_diagram_plot(**settings) | |
x_limit_min, x_limit_max = [-0.1], [0.9] | |
y_limit_min, y_limit_max = [-0.1], [0.9] | |
settings = { | |
'colour_cycle_map': 'rainbow', | |
'colour_cycle_count': len(colourspaces) | |
} | |
settings.update(kwargs) | |
cycle = colour_cycle(**settings) | |
for colourspace in colourspaces: | |
if colourspace == 'Pointer Gamut': | |
xy = np.asarray(POINTER_GAMUT_BOUNDARIES) | |
alpha_p, colour_p = 0.85, '0.95' | |
pylab.plot( | |
xy[..., 0], | |
xy[..., 1], | |
label='Pointer\'s Gamut', | |
color=colour_p, | |
alpha=alpha_p, | |
linewidth=2) | |
pylab.plot( | |
(xy[-1][0], xy[0][0]), (xy[-1][1], xy[0][1]), | |
color=colour_p, | |
alpha=alpha_p, | |
linewidth=2) | |
XYZ = Lab_to_XYZ( | |
LCHab_to_Lab(POINTER_GAMUT_DATA), POINTER_GAMUT_ILLUMINANT) | |
xy = XYZ_to_xy(XYZ, POINTER_GAMUT_ILLUMINANT) | |
pylab.scatter( | |
xy[..., 0], | |
xy[..., 1], | |
alpha=alpha_p / 2, | |
color=colour_p, | |
marker='+') | |
else: | |
colourspace, name = get_RGB_colourspace(colourspace), colourspace | |
r, g, b, _a = next(cycle) | |
P = colourspace.primaries | |
W = colourspace.whitepoint | |
pylab.plot( | |
(W[0], W[0]), (W[1], W[1]), | |
color=(r, g, b), | |
label=colourspace.name, | |
linewidth=2) | |
pylab.plot( | |
(W[0], W[0]), (W[1], W[1]), 'o', color=(r, g, b), linewidth=2) | |
pylab.plot( | |
(P[0, 0], P[1, 0]), (P[0, 1], P[1, 1]), | |
'o-', | |
color=(r, g, b), | |
linewidth=2) | |
pylab.plot( | |
(P[1, 0], P[2, 0]), (P[1, 1], P[2, 1]), | |
'o-', | |
color=(r, g, b), | |
linewidth=2) | |
pylab.plot( | |
(P[2, 0], P[0, 0]), (P[2, 1], P[0, 1]), | |
'o-', | |
color=(r, g, b), | |
linewidth=2) | |
x_limit_min.append(np.amin(P[..., 0]) - 0.1) | |
y_limit_min.append(np.amin(P[..., 1]) - 0.1) | |
x_limit_max.append(np.amax(P[..., 0]) + 0.1) | |
y_limit_max.append(np.amax(P[..., 1]) + 0.1) | |
settings.update({ | |
'legend': | |
True, | |
'legend_location': | |
'upper right', | |
'x_tighten': | |
True, | |
'y_tighten': | |
True, | |
'limits': (min(x_limit_min), max(x_limit_max), min(y_limit_min), | |
max(y_limit_max)), | |
'standalone': | |
True | |
}) | |
settings.update(kwargs) | |
boundaries(**settings) | |
decorate(**settings) | |
return display(**settings) | |
RGB_colourspaces_planckian_locus_CIE_1931_chromaticity_diagram_plot(['sRGB']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment