public static float[] convertRGBtoLAB(int rgb){
  float[] lab=new float[3];
  float fx, fy, fz;
  float eps=216.f / 24389.f;
  float k=24389.f / 27.f;
  float Xr=0.964221f;
  float Yr=1.0f;
  float Zr=0.825211f;
  float r=Color.red(rgb) / 255.f;
  float g=Color.green(rgb) / 255.f;
  float b=Color.blue(rgb) / 255.f;
  if (r <= 0.04045)   r=r / 12;
 else   r=(float)Math.pow((r + 0.055) / 1.055,2.4);
  if (g <= 0.04045)   g=g / 12;
 else   g=(float)Math.pow((g + 0.055) / 1.055,2.4);
  if (b <= 0.04045)   b=b / 12;
 else   b=(float)Math.pow((b + 0.055) / 1.055,2.4);
  float X=0.436052025f * r + 0.385081593f * g + 0.143087414f * b;
  float Y=0.222491598f * r + 0.71688606f * g + 0.060621486f * b;
  float Z=0.013929122f * r + 0.097097002f * g + 0.71418547f * b;
  float xr=X / Xr;
  float yr=Y / Yr;
  float zr=Z / Zr;
  if (xr > eps)   fx=(float)Math.pow(xr,1 / 3.);
 else   fx=(float)((k * xr + 16.) / 116.);
  if (yr > eps)   fy=(float)Math.pow(yr,1 / 3.);
 else   fy=(float)((k * yr + 16.) / 116.);
  if (zr > eps)   fz=(float)Math.pow(zr,1 / 3.);
 else   fz=(float)((k * zr + 16.) / 116);
  float Ls=(116 * fy) - 16;
  float as=500 * (fx - fy);
  float bs=200 * (fy - fz);
  lab[0]=(2.55f * Ls + .5f);
  lab[1]=(as + .5f);
  lab[2]=(bs + .5f);
  return lab;
}

public static float [ ] convertRGBtoLAB ( int rgb ) { float [ ] lab = new float [ 3 ] ; float fx , fy , fz ; float eps = 216.f / 24389.f ; float k = 24389.f / 27.f ; float Xr = 0.964221f ; float Yr = 1.0f ; float Zr = 0.825211f ; float r = Color . red ( rgb ) / 255.f ; float g = Color . green ( rgb ) / 255.f ; float b = Color . blue ( rgb ) / 255.f ; if ( r <= 0.04045 ) r = r / 12 ; else r = ( float ) Math . pow ( ( r + 0.055 ) / 1.055 , 2.4 ) ; if ( g <= 0.04045 ) g = g / 12 ; else g = ( float ) Math . pow ( ( g + 0.055 ) / 1.055 , 2.4 ) ; if ( b <= 0.04045 ) b = b / 12 ; else b = ( float ) Math . pow ( ( b + 0.055 ) / 1.055 , 2.4 ) ; float X = 0.436052025f * r + 0.385081593f * g + 0.143087414f * b ; float Y = 0.222491598f * r + 0.71688606f * g + 0.060621486f * b ; float Z = 0.013929122f * r + 0.097097002f * g + 0.71418547f * b ; float xr = X / Xr ; float yr = Y / Yr ; float zr = Z / Zr ; if ( xr > eps ) fx = ( float ) Math . pow ( xr , 1 / 3. ) ; else fx = ( float ) ( ( k * xr + 16. ) / 116. ) ; if ( yr > eps ) fy = ( float ) Math . pow ( yr , 1 / 3. ) ; else fy = ( float ) ( ( k * yr + 16. ) / 116. ) ; if ( zr > eps ) fz = ( float ) Math . pow ( zr , 1 / 3. ) ; else fz = ( float ) ( ( k * zr + 16. ) / 116 ) ; float Ls = ( 116 * fy ) - 16 ; float as = 500 * ( fx - fy ) ; float bs = 200 * ( fy - fz ) ; lab [ 0 ] = ( 2.55f * Ls + .5f ) ; lab [ 1 ] = ( as + .5f ) ; lab [ 2 ] = ( bs + .5f ) ; return lab ; }
converts an rgb packed int into l * a * b space , which is well - suited for finding perceptual differences in color
