# Creating a 1D spi1d shaper?

Hello, I have a tonemap based formula to shape the HDR into 0-1 range and want to create a 1D shaper with it. What would be the best way to do it?
`(x*(2.7*x+0.02))/(x*(2.25*x+0.9)+0.2)`
Currently I use a gizmo found here where I can expression-ridden build the curve and export as .spi1d but I have two issues, the precision is only 1024, and second it clamps at 1.0. I would like to know how to leave the ends open, as explained here in the figure 13. I’m using Nuke instead of Resolve because the shaper is going to be applied to ACEScg HDR whereas ACEScc space is LDR.

How is your Python? Colour Science for Python can write .spi1d LUTs.

``````>>> import colour
>>> import numpy as np
>>> x = np.linspace(0.0, 2.161202, 4096)
>>> table = (x*(2.7*x+0.02))/(x*(2.25*x+0.9)+0.2)
>>> LUT = colour.LUT1D(domain=[0.0, 2.161202], table=table)
>>> colour.write_LUT(LUT, 'shaper.spi1d')
True``````
1 Like

Thank you! Looks interesting. Python is not my forte, but I know some scripting languages so hopefully I’ll get by.

In terms of ‘leaving the end open’, a LUT is inherently limited to a range. Whether the output is extrapolated beyond that range is down to the implementation you use to apply the LUT.

If you need it to be trully unrestricted, you need to apply the transform mathematically, e.g. with the Expression node in Nuke; not with a LUT.

Oh, and one other thing. LUT support in Colour is a recent addition, so I don’t think is in a release version. You may need to grab the `develop` branch from GitHub.

My intention is to load the LUT through OCIO as a render tonemapper, I’m not sure OCIO suppports a mathematical transform definition (ctl?) so having a shaper/LUT that works up to 16.29 (and from 0.0028?) is sufficient.
It’s only for preview, when compositing/grading I can use the formula for more precision.

No. OCIO only supports LUTs for this kind of transform (matrices and a few other simple transforms can be applied mathematically).

If you replace the range numbers in my code with your desired range, you will create the LUT you want. I picked the range I did because it generates output ranged 0-1.

Yes, if I’m not wrong shaper LUTs are range dependent, so there’s not one-size-fits-all. I will make several then. As I learned in games they get the average luma in real time to derive x so the transform is dynamic. I’m foreseeing a combination of 4 shapers * 10 or so looks, and I’m not going to make 40 viewer transforms so I’ll most likely end conforming the look in Nuke and later making a viewer transform per project.

I just made a quick notebook that does generate the above LUT online: https://colab.research.google.com/drive/1O9C2IobnAIBZx3AM4hDM5oRdbKM7sK_z

I gave you edit rights @nick !

Cheers,

Thomas

1 Like

Installed numpy, scipy and colour-science succesfully for python 3.6.5 (“six” installed somehow along colour-science), but when executing the script it warns me:
module ‘colour’ has no attribute ‘lut1d’

I’m using a python that was already installed in my machine by Substance software, I know this could make it not work, but I’m not sure if installing another vanilla Python could clash with the installed one. I’m not a programmer, sorry for the burden.

*Installed colour-0.1.5 module and getting the same error

@Dogway : I’m a bit confusing, if you are on your local machine. The current built PIP version of colour-science does not have the above functionality yet, you would need to grab the latest version from the repo: https://github.com/colour-science/colour and add it to PYTHONPATH manually.

or alternatively, use the Google Colab notebook from above directly without having to install anything as it will be in the Cloud.

Cheers,

Thomas

1 Like