Linear RGB for Machado et al method?
Hi there, thank you so much for this implementation. I was exploring adapting it for my own purposes, and found a potential issue: currently, when using the Machado et al method, the function does not convert the input color to linear rgb before performing the matrix computation. When looking at the original paper, I didn't see the author specify whether the input values should be linear rgb or srgb, but based on context I believe it should be linear rgb.
Do you have more direct evidence that the operation should be performed on srgb, as in your implementation, or linear rgb, like the brettel method?
It is very plausible, that my implementation is wrong.
I agree with @ilikescience. The input color should be converted to linear RGB values, as the color transformation method described by Machado et al. uses linear light space (they tested real-life conditions). Our digital environments use gamma to encode and decode luminance; therefore, we need to account for it.
Also, thank you so much for this implementation, @MaPePeR, which, contrary to what you stated, is not entirely wrong :) It saved me hundred of hours of headaches :)
Below is my small contribution to your tremendous lift.
Include these functions right under getForSeverityStep around line 125:
function sRGBtoLinear(c) {
return c.map(value => value <= 0.04045 ? value / 12.92 : Math.pow((value + 0.055) / 1.055, 2.4));
}
function linearToSRGB(c) {
return c.map(value => value <= 0.0031308 ? 12.92 * value : 1.055 * Math.pow(value, 1 / 2.4) - 0.055);
}
And then just add this before and after the transformation, line 161:
// Convert the input to linear RGB
rgb = sRGBtoLinear(rgb.map(v => v / 255));
and change the result line 169 to:
// Convert back to sRGB and scale to 0-255
return linearToSRGB(result).map(v => Math.round(v * 255));
and...voila! :)
For reference, here is how pure red (#FF0000, [255, 0, 0]) was calculated before:
- Protanopia: [39, 29, 0]
- Deuteranopia: [94, 71, 0]
- Tritanopia: [255, 0, 1]
And once the correction is applied (which corresponds to what you can see on Adobe Color Accessibility Tool):
- Protanopia: [109, 95, 0]
- Deuteranopia: [163, 144, 0]
- Tritanopia: [255, 0, 15]
Thank you again :)
@t1wk Can you create a pull request with the changes, so I can merge it and you will be properly listed as a contributor?