Python - sRGB to Linear / Linear to sRGB

A quick note to just so I can keep track of the functions.

def srgb2lin(s):
    if s <= 0.0404482362771082:
        lin = s / 12.92
    else:
        lin = pow(((s + 0.055) / 1.055), 2.4)
    return lin


def lin2srgb(lin):
    if lin > 0.0031308:
        s = 1.055 * (pow(lin, (1.0 / 2.4))) - 0.055
    else:
        s = 12.92 * lin
    return s

Note that I picked up these functions somewhere on stackoverflow, I didn’t come up this any of it…

Sampling deep values

A quick note about sampling deep values in python in nuke.

Today, I was faced with a question that a quick google search could not answer so I thought I'd made a post about it.

How do you sample the values a the deep channel in python?

nuke.sample(node, channel, x, y) doesn't work on deep.

Nuke's help behind what it is, accessing this page took a bit longer than it should have: https://docs.thefoundry.co.uk/nuke/63/pythonreference/nuke.Node-class.html#deepSample

And so, here's how you do it :

node.deepSample(c, x, y, n)

  • c -> deep channel (deep.front, deep.back...) - string
  • x -> position to sample on the x axis - integer
  • y -> position to sample on the y axis - integer
  • n -> index of the sample - integer, -1 for the frontmost