Ahmad Lashgar, PhD
Home |
Resume |
Software |
X |
Blog |
Tools
Compare Color Gamuts using PythonApril 30th, 2022 - There are wide range of displays that we watch contents from daily. Every display has a unique color space. This defines the range of RGB colors representable on the display. This range is called color space gamut. The full range of colors visible by human eyes, as defined by CIE 1931, are shown in the figure below. TVs, monitors, cellphones, and video projectors have different capabilities in displaying colors. But we can name ITU-R BT 709 and sRGB as examples of most commonly supported color space gamuts on all displays. Color space gamut is defined by three primaries plus the white point in CIE xy space. For example, these are the three primaries and white point for ITU-R BT2020 color space:
p1 = [ 0.708, 0.292]
p2 = [ 0.17, 0.797]
p3 = [ 0.131, 0.046]
wp = [ 0.3127, 0.329]
We can draw the color gamut of the color space using the primaries and white point. The code below uses Python colour-science package for drawing the gamut:
from colour.plotting import plot_RGB_colourspaces_in_chromaticity_diagram_CIE1931
from colour.models.rgb import RGB_Colourspace
primaries = [ 0.708, 0.292, 0.17, 0.797, 0.131, 0.046 ]
whitepoint = [ 0.3127, 0.329]
cs1 = RGB_Colourspace("Gamut 1", primaries, whitepoint)
show_list = [cs1]
plot_RGB_colourspaces_in_chromaticity_diagram_CIE1931( show_list )
This would show the color gamut on the full CIE color range: To compare two or more color gamuts, create new gamut using RGB_Colourspace and add them to show_list:
p2 = [ 0.8, 0.3, 0.2, 0.6, 0.2, 0.1 ]
wp2 = [ 0.30, 0.29]
cs2 = RGB_Colourspace("Gamut 2", p2, wp2)
show_list = [cs1,cs2]
This would show two color gamuts on the full CIE color range: Following python packages are used in thie example:
python -m pip install colour-science PyQt5
That's it, I keep this guide short. colour-science library is rich and documentation is exemplary. Checkout the API and start playing with color. Download the full sample from here. Thanks for reading. Feel free to reach out if you had a question/comment. |