Plotting chromaticities using OIIO and Colour Science for Python

oiio
colour-science
python
plotting
openimageio
Tags: #<Tag:0x00007f3c5e2fa8e0> #<Tag:0x00007f3c5e2f9788> #<Tag:0x00007f3c5e2f8c70> #<Tag:0x00007f3c6806ffa8> #<Tag:0x00007f3c6806f468>

(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