Sigmoid Module Math?

I’d like to be able to replicate the tone curve aspect of the sigmoid module in high resolution 1D LUTs for use in DCP profiles and other editing apps but I’m struggling to figure out the math. I don’t really have any coding experience so I haven’t been able to dig into the code to figure it out yet. I’ve learned enough image processing math to be able to use Lattice (LUT creation/modification app with, I believe, python math expressions) to scale exposure and generate simple log-logistic curves (in the form of 1/(1+($x/.18)**-1.5) for example) but I can’t figure out exactly how the contrast and skew work or how to get the resulting curve to be centered around .18 rather than .5 so that it’s correct for linear data.

If anyone could point me in the right direction I’d appreciate it!

1 Like

Taking a quick scan there is more going on than just a simple curve with a skew and contrast parameter changing the shape… at least from what I can see…

Wow, yeah, I guess there is! :laughing: Do you know how I could see what’s happening in the “sigmoid_loglogistic_per_channel” program that it references? I’m assuming that’s where the actual math is?

sigmoid_loglogistic_per_channel is the OpenCL kernel. Probably a plain C implementation would be easier to follow.
See darktable/src/iop/sigmoid.c at 4be1794967b781942a8bb3abf3b1cd331bddbed4 · darktable-org/darktable · GitHub and below.

Maybe the curve explorer will also be useful:

I thought this referred to one of the color preservations modes but I would defer to @kofa as I know he is a far better source than me… I thought at one time I remember a discussion that the curves are treated for each channel and then the ratio is maintained… that would be similar to filmic and why the ratio option looks more like filmic…again just going on memory here I could likely find it if I went digging and then it would be accurate and not a memory… :slight_smile:

There are C functions for the two colour modes:

  • per-channel mode:
    – process_loglogistic_per_channel (if hue_preservation is practically disabled)
    – process_loglogistic_per_channel_interpolated (if hue_preservation >= 0.001)
  • RGB ratio: process_loglogistic_rgb_ratio

And there are the OpenCL implementations: kernel_sigmoid_loglogistic_per_channel, kernel_sigmoid_loglogistic_per_channel_interpolated and kernel_sigmoid_loglogistic_rgb_ratio. Those live in sigmoid.cl.

2 Likes

Fun that you want use the curve outside of darktable!

You might have a easier time generating the curve from the Python implementation I did:

Getting it to go through middle grey and having a orthogonal skew requires a bit of pre-computation of constants. Its much easier if you drop the skew part though.

Hope you manage to get it to work for your needs :slight_smile:

3 Likes