Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the HyAB color difference metric #328

Merged
merged 1 commit into from
May 7, 2023
Merged

Add the HyAB color difference metric #328

merged 1 commit into from
May 7, 2023

Conversation

Ogeon
Copy link
Owner

@Ogeon Ogeon commented May 6, 2023

Adds the HyAB color distance metric for Lab, Oklab and Luv. It's primarily only meant for CIELAB, but I figured it may translate well to the other two as well, since they have similar semantics.

I have also added a summary of the available difference metrics in the module description. It's not exactly precise or scientific, but may still be helpful.

Closed Issues

@Ogeon
Copy link
Owner Author

Ogeon commented May 6, 2023

@okaneco, you may want to have a look at this, so I don't make too many things up in the documentation. I would appreciate an extra pair of eyes, if you want to/have time. 🙂

@github-actions
Copy link

github-actions bot commented May 6, 2023

Benchmark for ce40517

Click to view benchmark
Test Base PR %
Cie family/lab to lch 3.1±0.01µs 3.1±0.11µs 0.00%
Cie family/lab to xyz 764.9±4.05ns 762.5±2.58ns -0.31%
Cie family/lch to lab 2.4±0.01µs 2.4±0.04µs 0.00%
Cie family/linsrgb to xyz 285.2±1.35ns 295.9±5.06ns +3.75%
Cie family/linsrgb to xyz - wide::f32x8 102.7±0.44ns 103.9±2.74ns +1.17%
Cie family/xyz to lab 21.1±0.11µs 21.2±0.38µs +0.47%
Cie family/xyz to yxy 654.0±2.63ns 655.9±2.86ns +0.29%
Cie family/yxy to xyz 528.5±2.01ns 528.6±4.25ns +0.02%
Matrix functions/matrix_inverse 11.6±0.07ns 11.6±0.12ns 0.00%
Matrix functions/multiply_3x3 10.4±0.04ns 10.5±0.05ns +0.96%
Matrix functions/multiply_rgb_to_xyz 6.4±0.04ns 6.4±0.05ns 0.00%
Matrix functions/multiply_xyz 6.4±0.03ns 6.4±0.05ns 0.00%
Matrix functions/multiply_xyz_to_rgb 6.4±0.10ns 6.4±0.03ns 0.00%
Matrix functions/rgb_to_xyz_matrix 30.1±0.13ns 30.1±0.12ns 0.00%
Rgb family/hsl to hsv 662.1±12.06ns 661.7±11.90ns -0.06%
Rgb family/hsl to linear hsl 12.1±0.06µs 12.1±0.08µs 0.00%
Rgb family/hsl to rgb 1998.1±9.27ns 1996.7±7.40ns -0.07%
Rgb family/hsv to hsl 812.8±29.04ns 806.5±3.14ns -0.78%
Rgb family/hsv to hwb 222.8±0.93ns 226.9±0.97ns +1.84%
Rgb family/hsv to linear hsv 10.8±0.05µs 10.7±0.08µs -0.93%
Rgb family/hsv to rgb 1915.4±26.74ns 1912.0±16.70ns -0.18%
Rgb family/hwb to hsv 481.2±10.36ns 481.1±10.25ns -0.02%
Rgb family/hwb to linear hwb 11.4±0.22µs 11.3±0.05µs -0.88%
Rgb family/linear hsl to hsl 10.7±0.05µs 10.7±0.05µs 0.00%
Rgb family/linear hsv to hsv 10.1±0.19µs 10.1±0.05µs 0.00%
Rgb family/linear hwb to hwb 10.8±0.04µs 10.8±0.05µs 0.00%
Rgb family/linsrgb to rgb 5.5±0.07µs 5.5±0.09µs 0.00%
Rgb family/linsrgb to rgb - wide::f32x8 5.5±0.04µs 5.5±0.04µs 0.00%
Rgb family/linsrgb_f32 to rgb_u8 908.5±3.25ns 912.2±3.47ns +0.41%
Rgb family/linsrgb_f64 to rgb_u8 1168.7±4.98ns 1168.7±9.02ns 0.00%
Rgb family/rgb to hsl 793.2±3.26ns 798.0±6.62ns +0.61%
Rgb family/rgb to hsl - wide::f32x8 499.0±2.41ns 498.9±3.79ns -0.02%
Rgb family/rgb to hsv 497.7±2.00ns 507.8±3.86ns +2.03%
Rgb family/rgb to hsv - wide::f32x8 436.2±2.76ns 436.7±10.07ns +0.11%
Rgb family/rgb to linsrgb 7.5±0.04µs 7.5±0.03µs 0.00%
Rgb family/rgb to linsrgb - wide::f32x8 3.7±0.04µs 3.7±0.06µs 0.00%
Rgb family/rgb_u8 to linsrgb_f32 334.3±1.37ns 333.7±1.87ns -0.18%
Rgb family/rgb_u8 to linsrgb_f64 340.8±3.22ns 328.5±1.22ns -3.61%
Rgb family/xyz to linsrgb 338.2±3.64ns 337.5±1.49ns -0.21%
Rgb family/xyz to linsrgb - wide::f32x8 102.7±0.52ns 103.2±0.79ns +0.49%

//! |-------|------------|----------|-------|
//! | [`Ciede2000`] | High | High for small differences, lower for large differences | The de-facto standard, but requires complex calculations to compensate for increased errors in certain areas of the CIE L\*a\*b\* (CIELAB) space.
//! | [`EuclideanDistance`] | Low | Medium to high for perceptually uniform spaces, otherwise low | Can be good enough for perceptually uniform spaces or as a "quick and dirty" check.
//! | [`HyAb`] | Low | High for large differences, compared to CIEDE2000, for CIE L\*a\*b\* (CIELAB) | Similar to Euclidean distance, but separates lightness and chroma more. Limited to Cartesian spaces with a lightness axis and a chroma plane.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think HyAb is presented as being a "good enough" option even for smaller differences according to the conclusion. It's not as accurate as Ciede2000 for small differences but the performance benefits outweigh the loss of accuracy for general purpose uses.

It is reasonable to conclude that the HyAB formula has the best correlation with visual observations for very large color differences. It has the best performance for the first category and third category of the first dataset. It
also holds up well for smaller color differences and thus is a good candidate formula for image processing and
computer vision applications.
...
So, the HyAB and HyCH could be used for small to large color difference calculation. However, the HyAB has a slightly better performance and the advantage of simpler computation.

In summary, something like

High accuracy for medium to large differences. Less accurate than Ciede2000 for small differences, but still performs well and is much less computationally expensive.

Everything else looks good 🙂

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yeah, I missed that part. I'll update it! I think I'll also highlight that the WCAG 2.1 contrast only checks lightness. Thanks for having a look and I hope you didn't mind the ping!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, glad to help.

Good idea on the highlight in the relative contrast notes. I would expand the explanation of computer graphics slightly,

Meant for checking contrast in computer graphics (such as between text and background colors)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's good to clarify. 👍

@Ogeon Ogeon force-pushed the hyab_color_distance branch from ab4dcbb to a6106e1 Compare May 7, 2023 08:41
@github-actions
Copy link

github-actions bot commented May 7, 2023

Benchmark for f911acf

Click to view benchmark
Test Base PR %
Cie family/lab to lch 3.1±0.01µs 3.1±0.02µs 0.00%
Cie family/lab to xyz 762.4±2.90ns 762.7±3.21ns +0.04%
Cie family/lch to lab 2.4±0.03µs 2.4±0.03µs 0.00%
Cie family/linsrgb to xyz 285.2±1.75ns 285.4±2.34ns +0.07%
Cie family/linsrgb to xyz - wide::f32x8 102.7±0.38ns 102.7±0.40ns 0.00%
Cie family/xyz to lab 21.1±0.18µs 21.2±0.29µs +0.47%
Cie family/xyz to yxy 653.9±2.83ns 658.3±7.86ns +0.67%
Cie family/yxy to xyz 527.6±2.74ns 527.8±2.34ns +0.04%
Matrix functions/matrix_inverse 11.6±0.05ns 11.6±0.05ns 0.00%
Matrix functions/multiply_3x3 10.4±0.04ns 10.5±0.08ns +0.96%
Matrix functions/multiply_rgb_to_xyz 6.4±0.03ns 6.4±0.02ns 0.00%
Matrix functions/multiply_xyz 6.4±0.03ns 6.4±0.02ns 0.00%
Matrix functions/multiply_xyz_to_rgb 6.4±0.02ns 6.4±0.03ns 0.00%
Matrix functions/rgb_to_xyz_matrix 30.1±0.13ns 30.1±0.12ns 0.00%
Rgb family/hsl to hsv 659.0±11.50ns 660.2±12.13ns +0.18%
Rgb family/hsl to linear hsl 12.6±0.05µs 12.3±0.05µs -2.38%
Rgb family/hsl to rgb 1998.2±14.00ns 1997.0±12.80ns -0.06%
Rgb family/hsv to hsl 805.9±10.90ns 806.1±10.47ns +0.02%
Rgb family/hsv to hwb 227.8±1.59ns 223.0±0.88ns -2.11%
Rgb family/hsv to linear hsv 10.8±0.04µs 10.9±0.06µs +0.93%
Rgb family/hsv to rgb 1901.1±15.42ns 1905.8±15.94ns +0.25%
Rgb family/hwb to hsv 481.0±10.93ns 480.4±9.95ns -0.12%
Rgb family/hwb to linear hwb 11.4±0.20µs 11.6±0.07µs +1.75%
Rgb family/linear hsl to hsl 11.1±0.04µs 10.7±0.08µs -3.60%
Rgb family/linear hsv to hsv 10.3±0.28µs 10.1±0.06µs -1.94%
Rgb family/linear hwb to hwb 11.0±0.05µs 10.8±0.06µs -1.82%
Rgb family/linsrgb to rgb 5.5±0.02µs 5.5±0.03µs 0.00%
Rgb family/linsrgb to rgb - wide::f32x8 5.5±0.03µs 5.5±0.03µs 0.00%
Rgb family/linsrgb_f32 to rgb_u8 909.3±4.77ns 910.8±16.97ns +0.16%
Rgb family/linsrgb_f64 to rgb_u8 1168.0±3.94ns 1168.7±5.14ns +0.06%
Rgb family/rgb to hsl 801.9±4.52ns 793.6±3.38ns -1.04%
Rgb family/rgb to hsl - wide::f32x8 497.8±2.11ns 498.1±1.59ns +0.06%
Rgb family/rgb to hsv 498.5±1.30ns 497.5±2.11ns -0.20%
Rgb family/rgb to hsv - wide::f32x8 435.3±2.01ns 434.6±2.52ns -0.16%
Rgb family/rgb to linsrgb 7.5±0.03µs 7.7±0.04µs +2.67%
Rgb family/rgb to linsrgb - wide::f32x8 3.7±0.02µs 3.7±0.01µs 0.00%
Rgb family/rgb_u8 to linsrgb_f32 332.4±9.25ns 328.6±1.15ns -1.14%
Rgb family/rgb_u8 to linsrgb_f64 331.0±9.40ns 329.9±2.53ns -0.33%
Rgb family/xyz to linsrgb 338.9±1.40ns 337.8±1.54ns -0.32%
Rgb family/xyz to linsrgb - wide::f32x8 103.3±1.31ns 102.7±0.48ns -0.58%

@Ogeon Ogeon force-pushed the hyab_color_distance branch from a6106e1 to 3d7f618 Compare May 7, 2023 17:56
@github-actions
Copy link

github-actions bot commented May 7, 2023

Benchmark for 0ce86d9

Click to view benchmark
Test Base PR %
Cie family/lab to lch 3.2±0.06µs 3.2±0.06µs 0.00%
Cie family/lab to xyz 763.1±10.16ns 763.3±12.58ns +0.03%
Cie family/lch to lab 2.4±0.06µs 2.4±0.05µs 0.00%
Cie family/linsrgb to xyz 308.9±5.72ns 309.0±4.69ns +0.03%
Cie family/linsrgb to xyz - wide::f32x8 99.7±1.34ns 101.5±2.92ns +1.81%
Cie family/xyz to lab 17.9±0.25µs 18.2±0.94µs +1.68%
Cie family/xyz to yxy 633.2±11.38ns 629.5±8.67ns -0.58%
Cie family/yxy to xyz 696.9±9.76ns 698.7±11.26ns +0.26%
Matrix functions/matrix_inverse 10.8±0.20ns 11.1±0.23ns +2.78%
Matrix functions/multiply_3x3 9.7±0.15ns 9.6±0.09ns -1.03%
Matrix functions/multiply_rgb_to_xyz 6.0±0.06ns 6.0±0.08ns 0.00%
Matrix functions/multiply_xyz 6.0±0.09ns 6.0±0.10ns 0.00%
Matrix functions/multiply_xyz_to_rgb 6.0±0.07ns 6.0±0.07ns 0.00%
Matrix functions/rgb_to_xyz_matrix 26.1±0.36ns 25.0±0.51ns -4.21%
Rgb family/hsl to hsv 647.1±11.51ns 651.9±12.19ns +0.74%
Rgb family/hsl to linear hsl 13.2±0.12µs 13.0±0.20µs -1.52%
Rgb family/hsl to rgb 2.1±0.03µs 2.1±0.02µs 0.00%
Rgb family/hsv to hsl 818.0±12.33ns 822.9±12.30ns +0.60%
Rgb family/hsv to hwb 232.9±3.04ns 237.0±2.80ns +1.76%
Rgb family/hsv to linear hsv 11.9±0.18µs 11.7±0.16µs -1.68%
Rgb family/hsv to rgb 1906.4±28.52ns 1897.2±31.97ns -0.48%
Rgb family/hwb to hsv 481.3±8.87ns 485.1±7.92ns +0.79%
Rgb family/hwb to linear hwb 12.6±0.23µs 12.3±0.14µs -2.38%
Rgb family/linear hsl to hsl 11.1±0.13µs 11.1±0.15µs 0.00%
Rgb family/linear hsv to hsv 10.3±0.21µs 10.2±0.14µs -0.97%
Rgb family/linear hwb to hwb 11.2±0.16µs 11.4±0.27µs +1.79%
Rgb family/linsrgb to rgb 6.0±0.07µs 5.9±0.14µs -1.67%
Rgb family/linsrgb to rgb - wide::f32x8 5.1±0.07µs 5.2±0.13µs +1.96%
Rgb family/linsrgb_f32 to rgb_u8 952.9±10.10ns 958.7±22.13ns +0.61%
Rgb family/linsrgb_f64 to rgb_u8 1218.3±18.57ns 1214.5±16.36ns -0.31%
Rgb family/rgb to hsl 849.4±15.93ns 846.6±11.73ns -0.33%
Rgb family/rgb to hsl - wide::f32x8 470.5±6.56ns 470.5±5.71ns 0.00%
Rgb family/rgb to hsv 513.8±6.80ns 520.6±6.57ns +1.32%
Rgb family/rgb to hsv - wide::f32x8 428.3±10.22ns 430.8±20.95ns +0.58%
Rgb family/rgb to linsrgb 8.5±0.13µs 8.3±0.19µs -2.35%
Rgb family/rgb to linsrgb - wide::f32x8 3.3±0.04µs 3.3±0.05µs 0.00%
Rgb family/rgb_u8 to linsrgb_f32 306.5±3.83ns 306.5±4.81ns 0.00%
Rgb family/rgb_u8 to linsrgb_f64 311.6±3.95ns 311.8±4.47ns +0.06%
Rgb family/xyz to linsrgb 353.8±5.18ns 359.0±9.60ns +1.47%
Rgb family/xyz to linsrgb - wide::f32x8 107.1±2.19ns 105.5±1.30ns -1.49%

@Ogeon
Copy link
Owner Author

Ogeon commented May 7, 2023

bors r+

@bors
Copy link
Contributor

bors bot commented May 7, 2023

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here.
For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.

@bors bors bot merged commit 48d6ff0 into master May 7, 2023
@bors bors bot deleted the hyab_color_distance branch May 7, 2023 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement HyAB color difference metric
2 participants