TomArrow
27th March 2022, 00:36
Wanna present a new little plugin I made: https://github.com/TomArrow/LabConvertAVS (download for x86 and x64 in Releases section)
I've always loved the way color manipulations work in LAB color space, for example saturation changes, and how the interaction of color and luma actually behaves in an expected organic way. Was never happy with being restricted to ugly HSL/HSV/YUV variants.
So here's a little plugin that converts an RGBPS linear sRGB clip (you can create that with avsresize for example) to L C hab. L C hab is a derivative of the normal LAB color space and is more intuitive in that C corresponds with saturation and hab corresponds with hue.
A nice use case, for example, is for HDR to SDR tonemapping, at least in my opinion. Let's say you do your tonemap with a plugin like DGHable. You can just do it straight on the RGB data but the obvious outcome will be that highlights become desaturated (which I find desirable) and get ugly hue shifts (not desirable). So I like to do my tonemap, and then keep the Luma and Saturation from the tonemap (I like desaturated highlights) and combine it with the original hue. Doing this via CombinePlanes in L C hab, I find the results very pleasing and organic.
Or you could just convert to L C hab and scale the saturation (C) via Expr() to add good looking saturation. Or reduce it, for that matter.
Readme:
LabConvert AVISynth plugin
Two functions:
----
- ConvertToLChab(clip)
----
Expects an RGBS (32 bit floating point planar RGB) input clip in linear sRGB and returns a YUV444PS (32 bit floating point planar YUV).
It performs a conversion to the L C hab color space, which is a variation of LAB.
L corresponds with luminance, C with saturation and hab with the hue.
This allows for very targeted adjustments of colors, replacing luma/sat/hue planes and so forth, in a color space that does this in a beautiful way.
The color gamut is not limited to sRGB (negative values are allowed) and the conversion should not clamp values. Internally the floating point sRGB values are converted to XYZ, then to LAB and then finally to L C hab.
----
- ConvertFromLChab(clip)
----
1:1 reversal of ConvertToLChab.
----
Example use cases:
----
1. Convert two clips to LChab and then use CombinePlanes to combine the luminance, saturation and hue info of both clips in any desired way.
2. Convert to LChab and then manipulate the saturation channel (for example with Expr) for pleasing and natural looking saturation changes.
----
Note about YUV
----
The LChab clips are returned as YUV because it semantically made sense to me. However obviously they are not traditional YUV information, they are merely packaged as such, so your work on that data needs to be conscious. Do not blindly expect existing plugins to give reasonable results when feeding the LChab YUV clip into them.
If you need to manipulate the LChab data with functions that only accept RGB, use CombinePlanes to reinterpret the YUV data as RGB.
Hope it will be of some use to someone.
Note: This is not really optimized so the performance is not ideal. The conversion functions sadly use stuff like cubic roots and branching so I don't know how much can be done about it. I'm sure it could be sped up by talented hands (read: not by mine); feel free to send pull requests on github. For now, just consider it something to use when quality matters more than speed.
I've always loved the way color manipulations work in LAB color space, for example saturation changes, and how the interaction of color and luma actually behaves in an expected organic way. Was never happy with being restricted to ugly HSL/HSV/YUV variants.
So here's a little plugin that converts an RGBPS linear sRGB clip (you can create that with avsresize for example) to L C hab. L C hab is a derivative of the normal LAB color space and is more intuitive in that C corresponds with saturation and hab corresponds with hue.
A nice use case, for example, is for HDR to SDR tonemapping, at least in my opinion. Let's say you do your tonemap with a plugin like DGHable. You can just do it straight on the RGB data but the obvious outcome will be that highlights become desaturated (which I find desirable) and get ugly hue shifts (not desirable). So I like to do my tonemap, and then keep the Luma and Saturation from the tonemap (I like desaturated highlights) and combine it with the original hue. Doing this via CombinePlanes in L C hab, I find the results very pleasing and organic.
Or you could just convert to L C hab and scale the saturation (C) via Expr() to add good looking saturation. Or reduce it, for that matter.
Readme:
LabConvert AVISynth plugin
Two functions:
----
- ConvertToLChab(clip)
----
Expects an RGBS (32 bit floating point planar RGB) input clip in linear sRGB and returns a YUV444PS (32 bit floating point planar YUV).
It performs a conversion to the L C hab color space, which is a variation of LAB.
L corresponds with luminance, C with saturation and hab with the hue.
This allows for very targeted adjustments of colors, replacing luma/sat/hue planes and so forth, in a color space that does this in a beautiful way.
The color gamut is not limited to sRGB (negative values are allowed) and the conversion should not clamp values. Internally the floating point sRGB values are converted to XYZ, then to LAB and then finally to L C hab.
----
- ConvertFromLChab(clip)
----
1:1 reversal of ConvertToLChab.
----
Example use cases:
----
1. Convert two clips to LChab and then use CombinePlanes to combine the luminance, saturation and hue info of both clips in any desired way.
2. Convert to LChab and then manipulate the saturation channel (for example with Expr) for pleasing and natural looking saturation changes.
----
Note about YUV
----
The LChab clips are returned as YUV because it semantically made sense to me. However obviously they are not traditional YUV information, they are merely packaged as such, so your work on that data needs to be conscious. Do not blindly expect existing plugins to give reasonable results when feeding the LChab YUV clip into them.
If you need to manipulate the LChab data with functions that only accept RGB, use CombinePlanes to reinterpret the YUV data as RGB.
Hope it will be of some use to someone.
Note: This is not really optimized so the performance is not ideal. The conversion functions sadly use stuff like cubic roots and branching so I don't know how much can be done about it. I'm sure it could be sped up by talented hands (read: not by mine); feel free to send pull requests on github. For now, just consider it something to use when quality matters more than speed.