Module ij
Package ij.process

Class ColorSpaceConverter

java.lang.Object
ij.process.ColorSpaceConverter

public class ColorSpaceConverter
extends java.lang.Object
ColorSpaceConverter
Author:
dvs, hlp Created Jan 15, 2004 Version 3 posted on ImageJ Mar 12, 2006 by Duane Schwartzwald vonschwartzwalder at mac.com Version 4 created Feb. 27, 2007 by Harry Parker, harrylparker at yahoo dot com, corrects RGB to XYZ (and LAB) conversion.
  • Field Summary

    Fields 
    Modifier and Type Field Description
    double[] chromaD50
    reference white in xyY coordinates
    double[] chromaD55  
    double[] chromaD65  
    double[] chromaD75  
    double[] chromaWhitePoint  
    double[] D50
    reference white in XYZ coordinates
    double[] D55  
    double[] D65  
    double[] D75  
    double[][] M
    sRGB to XYZ conversion matrix
    double[][] Mi
    XYZ to sRGB conversion matrix
    double[] whitePoint  
  • Constructor Summary

    Constructors 
    Constructor Description
    ColorSpaceConverter()
    Default constructor; uses D65 for the white point
    ColorSpaceConverter​(java.lang.String white)
    Constructor for setting a non-default white point
  • Method Summary

    Modifier and Type Method Description
    int[] HSBtoRGB​(double[] HSB)  
    int[] HSBtoRGB​(double H, double S, double B)  
    ImagePlus LabToRGB​(ImagePlus img)
    Converts a Lab stack into an RGB image.
    int[] LABtoRGB​(double[] Lab)  
    int[] LABtoRGB​(double L, double a, double b)
    Convert LAB to RGB.
    double[] LABtoXYZ​(double[] Lab)
    Convert LAB to XYZ.
    double[] LABtoXYZ​(double L, double a, double b)
    Convert LAB to XYZ.
    double[] RGBtoHSB​(int[] RGB)  
    double[] RGBtoHSB​(int R, int G, int B)  
    double[] RGBtoLAB​(int rgb)  
    double[] RGBtoLAB​(int[] RGB)  
    ImagePlus RGBToLab​(ImagePlus img)
    Converts an RGB image into a Lab stack.
    double[] RGBtoXYZ​(int[] RGB)
    Convert RGB to XYZ
    double[] RGBtoXYZ​(int R, int G, int B)
    Convert RGB to XYZ
    double[] xyYtoXYZ​(double[] xyY)  
    double[] xyYtoXYZ​(double x, double y, double Y)  
    double[] XYZtoLAB​(double[] XYZ)
    Convert XYZ to LAB.
    double[] XYZtoLAB​(double X, double Y, double Z)
    Convert XYZ to LAB.
    int[] XYZtoRGB​(double[] XYZ)
    Convert XYZ to RGB
    int[] XYZtoRGB​(double X, double Y, double Z)
    Convert XYZ to RGB.
    double[] XYZtoxyY​(double[] XYZ)  
    double[] XYZtoxyY​(double X, double Y, double Z)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • D50

      public double[] D50
      reference white in XYZ coordinates
    • D55

      public double[] D55
    • D65

      public double[] D65
    • D75

      public double[] D75
    • whitePoint

      public double[] whitePoint
    • chromaD50

      public double[] chromaD50
      reference white in xyY coordinates
    • chromaD55

      public double[] chromaD55
    • chromaD65

      public double[] chromaD65
    • chromaD75

      public double[] chromaD75
    • chromaWhitePoint

      public double[] chromaWhitePoint
    • M

      public double[][] M
      sRGB to XYZ conversion matrix
    • Mi

      public double[][] Mi
      XYZ to sRGB conversion matrix
  • Constructor Details

    • ColorSpaceConverter

      public ColorSpaceConverter()
      Default constructor; uses D65 for the white point
    • ColorSpaceConverter

      public ColorSpaceConverter​(java.lang.String white)
      Constructor for setting a non-default white point
      Parameters:
      white - "d50", "d55", "d65" or "d75"
  • Method Details

    • HSBtoRGB

      public int[] HSBtoRGB​(double H, double S, double B)
      Parameters:
      H - Hue angle/360 (0..1)
      S - Saturation (0..1)
      B - Value (0..1)
      Returns:
      RGB values
    • HSBtoRGB

      public int[] HSBtoRGB​(double[] HSB)
    • LABtoRGB

      public int[] LABtoRGB​(double L, double a, double b)
      Convert LAB to RGB.
      Parameters:
      L -
      a -
      b -
      Returns:
      RGB values
    • LABtoRGB

      public int[] LABtoRGB​(double[] Lab)
      Parameters:
      Lab -
      Returns:
      RGB values
    • LABtoXYZ

      public double[] LABtoXYZ​(double L, double a, double b)
      Convert LAB to XYZ.
      Parameters:
      L -
      a -
      b -
      Returns:
      XYZ values
    • LABtoXYZ

      public double[] LABtoXYZ​(double[] Lab)
      Convert LAB to XYZ.
      Parameters:
      Lab -
      Returns:
      XYZ values
    • RGBtoHSB

      public double[] RGBtoHSB​(int R, int G, int B)
      Parameters:
      R - Red in range 0..255
      G - Green in range 0..255
      B - Blue in range 0..255
      Returns:
      HSB values: H is 0..360 degrees / 360 (0..1), S is 0..1, B is 0..1
    • RGBtoHSB

      public double[] RGBtoHSB​(int[] RGB)
    • RGBtoLAB

      public double[] RGBtoLAB​(int rgb)
      Parameters:
      rgb - RGB value
      Returns:
      Lab values
    • RGBtoLAB

      public double[] RGBtoLAB​(int[] RGB)
      Parameters:
      RGB -
      Returns:
      Lab values
    • RGBtoXYZ

      public double[] RGBtoXYZ​(int R, int G, int B)
      Convert RGB to XYZ
      Parameters:
      R -
      G -
      B -
      Returns:
      XYZ in double array.
    • RGBtoXYZ

      public double[] RGBtoXYZ​(int[] RGB)
      Convert RGB to XYZ
      Parameters:
      RGB -
      Returns:
      XYZ in double array.
    • xyYtoXYZ

      public double[] xyYtoXYZ​(double x, double y, double Y)
      Parameters:
      x -
      y -
      Y -
      Returns:
      XYZ values
    • xyYtoXYZ

      public double[] xyYtoXYZ​(double[] xyY)
      Parameters:
      xyY -
      Returns:
      XYZ values
    • XYZtoLAB

      public double[] XYZtoLAB​(double X, double Y, double Z)
      Convert XYZ to LAB.
      Parameters:
      X -
      Y -
      Z -
      Returns:
      Lab values
    • XYZtoLAB

      public double[] XYZtoLAB​(double[] XYZ)
      Convert XYZ to LAB.
      Parameters:
      XYZ -
      Returns:
      Lab values
    • XYZtoRGB

      public int[] XYZtoRGB​(double X, double Y, double Z)
      Convert XYZ to RGB.
      Parameters:
      X -
      Y -
      Z -
      Returns:
      RGB in int array.
    • XYZtoRGB

      public int[] XYZtoRGB​(double[] XYZ)
      Convert XYZ to RGB
      Parameters:
      XYZ - in a double array.
      Returns:
      RGB in int array.
    • XYZtoxyY

      public double[] XYZtoxyY​(double X, double Y, double Z)
      Parameters:
      X -
      Y -
      Z -
      Returns:
      xyY values
    • XYZtoxyY

      public double[] XYZtoxyY​(double[] XYZ)
      Parameters:
      XYZ -
      Returns:
      xyY values
    • RGBToLab

      public ImagePlus RGBToLab​(ImagePlus img)
      Converts an RGB image into a Lab stack.
    • LabToRGB

      public ImagePlus LabToRGB​(ImagePlus img)
      Converts a Lab stack into an RGB image.