Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I had some problems using the code in @finw's answer. I believe they were mostly due to the fact that to do a CIELab conversion you should specify an illuminant:</p> <p><a href="http://en.wikipedia.org/wiki/Standard_illuminant" rel="noreferrer">http://en.wikipedia.org/wiki/Standard_illuminant</a></p> <p>One of the popular standards is <a href="http://en.wikipedia.org/wiki/Standard_illuminant#Illuminant_series_D" rel="noreferrer">D50</a>, which is basically just a standard daylight. Because @finw's code doesn't have the correction for illumination, the colors that are supposed to be neutral gray come out slightly tinted. One way of checking this is to try:</p> <pre><code> float[] g = { 50.0f, 0f, 0f }; CIELab.getInstance().toRGB(g); for (float f : g) System.out.println(f); </code></pre> <p>You should get roughly the same number on all three channels, but you end up with an RGB profile that's noticeably (albeit slightly) blue. I'm sure it is possible to correct this in @finw's code, but after a bit of playing with it and searching around, I found some excellent conversion code here:</p> <p><a href="http://www.f4.fhtw-berlin.de/~barthel/ImageJ/ColorInspector//HTMLHelp/farbraumJava.htm" rel="noreferrer">http://www.f4.fhtw-berlin.de/~barthel/ImageJ/ColorInspector//HTMLHelp/farbraumJava.htm</a></p> <p>For completeness, here it is.</p> <pre><code>public void rgb2lab(int R, int G, int B, int[] lab) { //http://www.brucelindbloom.com float r, g, b, X, Y, Z, fx, fy, fz, xr, yr, zr; float Ls, as, bs; float eps = 216.f/24389.f; float k = 24389.f/27.f; float Xr = 0.964221f; // reference white D50 float Yr = 1.0f; float Zr = 0.825211f; // RGB to XYZ r = R/255.f; //R 0..1 g = G/255.f; //G 0..1 b = B/255.f; //B 0..1 // assuming sRGB (D65) if (r &lt;= 0.04045) r = r/12; else r = (float) Math.pow((r+0.055)/1.055,2.4); if (g &lt;= 0.04045) g = g/12; else g = (float) Math.pow((g+0.055)/1.055,2.4); if (b &lt;= 0.04045) b = b/12; else b = (float) Math.pow((b+0.055)/1.055,2.4); X = 0.436052025f*r + 0.385081593f*g + 0.143087414f *b; Y = 0.222491598f*r + 0.71688606f *g + 0.060621486f *b; Z = 0.013929122f*r + 0.097097002f*g + 0.71418547f *b; // XYZ to Lab xr = X/Xr; yr = Y/Yr; zr = Z/Zr; if ( xr &gt; eps ) fx = (float) Math.pow(xr, 1/3.); else fx = (float) ((k * xr + 16.) / 116.); if ( yr &gt; eps ) fy = (float) Math.pow(yr, 1/3.); else fy = (float) ((k * yr + 16.) / 116.); if ( zr &gt; eps ) fz = (float) Math.pow(zr, 1/3.); else fz = (float) ((k * zr + 16.) / 116); Ls = ( 116 * fy ) - 16; as = 500*(fx-fy); bs = 200*(fy-fz); lab[0] = (int) (2.55*Ls + .5); lab[1] = (int) (as + .5); lab[2] = (int) (bs + .5); } </code></pre> <p>In my tests, it produces gray values that are appropriately chroma-free, and it is much speedier to boot.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload