colour-science / colour

Colour Science for Python
https://www.colour-science.org
BSD 3-Clause "New" or "Revised" License
2.07k stars 258 forks source link

Implement support for "Blackmagic Design" colourspaces. #591

Open nick-shaw opened 4 years ago

nick-shaw commented 4 years ago

While the colour encodings of Blackmagic cameras are not published, the primaries of the various colour spaces can be displayed on the CIE plot 'scope in DaVinci Resolve.

The transfer functions are available only as 1D LUTs or hard coded internal transforms in Resolve. Can we create colourspaces which use LUTs, rather than functions? Would the LUT table need to be included in the colourspace file, or could it be a separate file?

nick-shaw commented 4 years ago

Would the correct approach be to add a datasets folder under transfer_functions and declare all the BMD transfer functions as arrays there?

sobotka commented 4 years ago

I wonder if the generic log-like approach with breakpoint can be solved for?

KelSolaar commented 4 years ago

Would the correct approach be to add a datasets folder under transfer_functions and declare all the BMD transfer functions as arrays there?

Sounds good yeah!

Can we create colourspaces which use LUTs, rather than functions?

Sure, the transfer functions are just callables, so any callable will work here!

I wonder if the generic log-like approach with breakpoint can be solved for?

If shown it matches really nicely why not!

nick-shaw commented 4 years ago

Work in progress version of Blackmagic colour spaces at https://github.com/nick-shaw/colour/tree/feature/blackmagic

KelSolaar commented 4 years ago

So here is something we could roll to lazily load the data: https://colab.research.google.com/drive/1RbAhKB8JM_X-LMkSSHY3OukcW1g0O_ni?usp=sharing

The first time you get the value for Luke, the function is evaluated and its output is stored in-place of the original callable. We could use that approach to have the CSV files loaded lazily that way.

KelSolaar commented 4 years ago

@nick-shaw : I pushed the new colour.utilities.LazyCaseInsensitiveMapping class, so if you rebase, you should get access to it!

Usage should be simple, let me know if you have any issue!

KelSolaar commented 3 years ago

Occurred to me while creating #648 and #649 that we never finished those!

cessen commented 2 years ago

An email conversation I had with @sobotka led me here (thanks Troy!). It looks like I've been duplicating some effort. I recently published this:

https://psychopath.io/post/2022_04_23_blackmagic_design_color_spaces

Among other things, I derived very precise formulas for most of Blackmagic's log transfer functions. Just thought I'd let you guys know in case it's useful to you!

KelSolaar commented 2 years ago

Hi Nathan,

We never rolled those because BMD released Gen 5 and we let the Gen 4 on the side. I reckon this would still be useful to have. Between @nick-shaw, @KevinJW and I, we have three notebooks to fit them using the CLF log functions.

Posting them for reference:

@nick-shaw : What do you reckon we should do?

cessen commented 2 years ago

Ah, very cool!

It looks like we reported different error metrics. I used relative error, whereas it looks like all the notebooks use absolute difference.

For reference, here are the absolute differences of my fits:

4K Film:

4.6K Film Gen 3:

Broadcast Film Gen 4:

Film:

Pocket 4K Film Gen 4:

Pocket 6K Film Gen 4:

(Note that my fits for the Pocket Film functions are comparatively poor. See footnote 11 in my post for why. That doesn't change the fact that they are comparatively poor, of course.)

According to this metric, it looks like my fits aren't quite as good as those in the notebooks.

I am curious what the relative errors of the notebooks are, however, as IMO that's a better error metric for color transfer functions: small differences near zero are more important than small differences at larger magnitudes. I suspect your fits are still better than mine even by that metric, but it might be worth checking.

~If needed, I'm also happy to convert my fits to the same equation form as the rest of you, for convenience.~ (Updated to a more standard natural log form in my post.)