Plotting chromaticities using OIIO and Colour Science for Python

oiio
colour-science
python
plotting
openimageio
Tags: #<Tag:0x00007f3c681b9f80> #<Tag:0x00007f3c681b9df0> #<Tag:0x00007f3c681b9cb0> #<Tag:0x00007f3c681b9b70> #<Tag:0x00007f3c681b9238>

(Christophe Brejon) #1

Hello @nick, sorry to bother you. I was wondering if you could help me to plot the gamut of an image. Are you using a colour science package? Thanks for your help! Chris


Colour artefacts or breakup using ACES
(Nick Shaw) #2

I am using Colour Science for Python:

https://colour.readthedocs.io/en/develop/generated/colour.plotting.RGB_chromaticity_coordinates_chromaticity_diagram_plot_CIE1931.html


(Christophe Brejon) #3

Thanks @nick ! That’s great! We’ll have a look!
Chris


(Christophe Brejon) #4

@nick So we were having a look at how to plot the gamut of an image with colour science. It looks like we need to install OIIO.
Here is our script:

import colour
import colour.plotting

RGB = colour.read_image(’/home/ryuu/PROJECTS/IMGDP_WEBSITE/resource/image/member/256/ryuu.png’)
RGB = RGB[…, 0:3] # Discarding alpha channel.
XYZ = colour.sRGB_to_XYZ(RGB)

colour.plotting.image_plot(XYZ, text_parameters={‘text’: ‘sRGB to XYZ’})

It gives us this error:

Traceback (most recent call last):
File “plot.py”, line 4, in
RGB = colour.read_image(’/home/ryuu/PROJECTS/IMGDP_WEBSITE/resource/image/member/256/ryuu.png’)
File “/home/ryuu/.local/lib/python3.7/site-packages/colour/io/image.py”, line 85, in read_image
if is_openimageio_installed(raise_exception=True):
File “/home/ryuu/.local/lib/python3.7/site-packages/colour/utilities/common.py”, line 183, in is_openimageio_installed
‘are not available: “{0}”.’).format(error))
ImportError: “OpenImageIO” related Api features are not available: “No module named ‘OpenImageIO’”.

Thanks for your help…

Chris


(Nick Shaw) #5

That is correct. Colour relies on OIIO for image reading. I have had issues myself making that dependency work, so am not the best person to help.

But the plotting functions of Colour simply plot from a NumPy array of colour triples, so any way of reading an image into that will work. For 8-bit integer image formats you can simply use PIL.

EDIT: RGB_chromaticity_coordinates_chromaticity_diagram_plot_CIE1931() expects linear input, so remember to linearise the values in your NumPy array if necessary before plotting.


(Christophe Brejon) #6

Thanks @nick! We will have a try. Have a nice week-end!
Chris


(Cédric Chapeleau) #7

Hi @nick,
I’m working as a technical director with @ChrisBrejon. I’ve installed PIL on my server. OCIIO seams to have a lot of dependencies, to much complicated for me I think. I will try to do same tests as soon as possible. Thanks for your help++

Cédric.


(Thomas Mansencal) #8

@ryuu: It seems like you guys are using a Unix flavour (Linux or macOS) given the paths in the traceback. OIIO should be relatively easy to compile on both and I highly recommend that you give it stab as it will allow you to use some of his tools such as oiiotool which are brilliant. With the Python bindings you will be able to process images with Colour and Numpy which might also be very useful. Let me know and maybe I can help you for the compilation.

Cheers,

Thomas


(Christophe Brejon) #9

Thanks @Thomas_Mansencal! That;s awesome! We’ll let you know how this goes! Much appreciated mate! :wink:


(Christophe Brejon) #10

Thanks @sdyer for creating this thread! So sorry, I did not mean to hack the previous page! Chris


(Attila Bakos) #11

I’m not a linux expert, I spent a whole afternoon solving dependency problems with OIIO, but it’s finally working. I use RGB_chromaticity_coordinates_chromaticity_diagram_plot_CIE1931 to plot RGB arrays in a given color space, but it would be great if I could see other colorspaces in the same diagram as well. Can someone help me how to do that?


(Thomas Mansencal) #12

Hi @Attila_Bakos,

The following should work, not this uses the latest develop branch but 0.3.11 should have same feature, note that the colour.plotting.RGB_chromaticity_coordinates_chromaticity_diagram_plot_CIE1931 definition has been renamed:

import numpy as np
from colour.plotting import *

plot_RGB_chromaticities_in_chromaticity_diagram_CIE1931(
    np.random.random([64, 64, 3]),
    'sRGB',
    colourspaces=['ACEScg']
)

Cheers,

Thomas


(Attila Bakos) #13

Thanks a lot, it’s working :slight_smile: