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

[WIP] Restore the proper scale of Lab and Lch #57

Closed
wants to merge 1 commit into from
Closed

Conversation

Ogeon
Copy link
Owner

@Ogeon Ogeon commented Feb 25, 2016

This restores the scale of Lab and Lch to be the same as in all of the specifications within reach. That is:

  • Lab::l and Lch::l goes from 0 to 100,
  • Lab::a and Lab::b goes from -128 to 127,
  • Lch::chroma goes from 0 to about 128-181.

This is a breaking change, since everything that uses these values directly will be wrong. Closes #49.

@Ogeon
Copy link
Owner Author

Ogeon commented Feb 25, 2016

The tests are still wrong and needs to be tweaked. Some of the inaccuracies are huge, like

    left = Lab { l: 91.11652, a: -51.481186, b: -14.387321 }
    right = Lab { l: 91.12, a: -48.08, b: -14.14 }

@sidred
Copy link
Contributor

sidred commented Feb 26, 2016

I've used a tolerance of 0.05 which translates to 5 when scaled.

I wonder if this is due to the differences in the default white point being used

pub const X_N: f64 = 0.95047;
pub const Y_N: f64 = 1.0;
pub const Z_N: f64 = 1.08883;

@sidred
Copy link
Contributor

sidred commented Feb 26, 2016

Nope. Color mine uses the same values:

        final double REF_X = 95.047; // Observer= 2°, Illuminant= D65
        final double REF_Y = 100.000;
        final double REF_Z = 108.883;

But the formula in color mine is incorrect

        final double REF_X = 95.047; // Observer= 2°, Illuminant= D65
        final double REF_Y = 100.000;
        final double REF_Z = 108.883;

        double x = pivotXyz(xyz.X / REF_X);
        double y = pivotXyz(xyz.Y / REF_Y);
        double z = pivotXyz(xyz.Z / REF_Z);

        return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z));

Its not using the transformation function

        fn convert<T: Float>(c: T) -> T {
            let epsilon: T = (flt::<T,_>(6.0 / 29.0)).powi(3);
            let kappa: T = flt(841.0 / 108.0);
            let delta: T = flt(4.0 / 29.0);
            if c > epsilon {
                c.powf(T::one() / flt(3.0))
            } else {
                (kappa * c ) + delta
            }
        }

I guess we need a better set of tests

@sidred
Copy link
Contributor

sidred commented Feb 26, 2016

We have a test for Xyz <-> Yxy, already from the CIE tables.

https://www.rit.edu/cos/colorscience/rc_useful_data.php has a few calculated values for Xyz, Lab and Lch ( CIEDE200 Color Difference formula, Pointer data). But it uses a 10 degree observer.

This should cover the CIE spaces.

http://stackoverflow.com/questions/3620663/color-theory-how-to-convert-munsell-hvc-to-rgb-hsb-hsl

points to http://www.cis.rit.edu/research/mcsl2/online/real_sRGB.xls which has rgb to xyz and yxy conversions.

The rgb variants conversions (hsl, hsv, hwb etc.) need to be figured out

Just adding it here for reference if the tests need to be updated.

@Ogeon
Copy link
Owner Author

Ogeon commented Feb 26, 2016

Thanks, I'll take a look at them later and see if it's possible to piece things together.

@homu
Copy link
Contributor

homu commented Mar 5, 2016

☔ The latest upstream changes (presumably #56) made this pull request unmergeable. Please resolve the merge conflicts.

@Ogeon
Copy link
Owner Author

Ogeon commented Mar 6, 2016

Turns out the accuracy of the Yxy values were too low, so I'm currently working my way through them, adding more decimals.

@sidred
Copy link
Contributor

sidred commented Mar 10, 2016

So the actual scaling part is done? Is it just the tests remaining?

@Ogeon
Copy link
Owner Author

Ogeon commented Mar 10, 2016

Yes, unless I forgot something. I'm pretty much just copy-pasting XYZ numbers to the easyrgb calculator, dividing them by 100, converting, and copy-pasting the xyY numbers back.

@sidred
Copy link
Contributor

sidred commented Mar 11, 2016

Closed by #61

@Ogeon Ogeon closed this Mar 11, 2016
@Ogeon Ogeon deleted the lab_lch_scale branch March 11, 2016 11:55
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.

3 participants