public final class ColorSpaceConversion
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static ij.process.ColorProcessor |
labToColorProcessor(VectorProcessor vp)
Convert between CIE L*a*b* and RGB color image representation.
|
static void |
labToXYZ(float[] lab,
float[] xyz)
Conversion from CIE L*a*b* to CIE XYZ assuming Observer.
|
static VectorProcessor |
labToXYZVectorProcessor(VectorProcessor vp)
Convert between CIE L*a*b* and XYZ color image representation.
|
static VectorProcessor |
rgbToLabVectorProcessor(ij.process.ColorProcessor cp)
Convert between RGB and CIE L*a*b* color image representation.
|
static void |
rgbToXYZ(float[] rgb,
float[] xyz)
sRGB to XYZ conversion based on conversion coefficients at: http://www.brucelindbloom.com/Eqn_RGB_to_XYZ.html
See also conversion from sRGB to CIE XYZ as defined in the IEC 619602-1 standard (http://www.colour.org/tc8-05/Docs/colorspace/61966-2-1.pdf), though it uses approximated coefficients. |
static VectorProcessor |
rgbToXYZVectorProcessor(ij.process.ColorProcessor cp)
Convert between sRGB and XYZ color image representation.
|
static ij.process.ByteProcessor[] |
rgbToYCbCr(ij.process.ColorProcessor rgb)
Converts image pixels from RGB color space to YCbCr color space.
|
static ij.process.ByteProcessor[] |
rgbToYCbCr(ij.process.ColorProcessor src,
ProgressListener progressListener)
Converts image pixels from RGB color space to YCbCr color space.
|
static ij.process.ColorProcessor |
xyzToColorProcessor(VectorProcessor vp)
Convert between XYZ and RGB color image representation.
|
static void |
xyzToLab(float[] xyz,
float[] lab)
Conversion from CIE XYZ to CIE L*a*b* assuming Observer.
|
static VectorProcessor |
xyzToLabVectorProcessor(VectorProcessor vp)
Convert between CIE XYZ and L*a*b* color image representation.
|
static void |
xyzToRGB(float[] xyz,
float[] rgb)
XYZ to sRGB conversion based on conversion coefficients at: http://www.brucelindbloom.com/Eqn_XYZ_to_RGB.html
Conversion from CIE XYZ to sRGB as defined in the IEC 619602-1 standard
(http://www.colour.org/tc8-05/Docs/colorspace/61966-2-1.pdf)
|
static void |
ycbcrToRGB(byte[] ybr,
byte[] rgb)
Converts image pixels from RGB color space to YCbCr color space.
|
static ij.process.ColorProcessor |
ycbcrToRGB(ij.process.ByteProcessor[] ybr)
Converts image pixels from RGB color space to YCbCr color space.
|
static ij.process.ColorProcessor |
ycbcrToRGB(ij.process.ByteProcessor[] ybr,
ProgressListener progressListener)
Converts image pixels from RGB color space to YCbCr color space.
|
public static void xyzToRGB(float[] xyz,
float[] rgb)
r_linear = +3.2404542 * X - 1.5371385 * Y - 0.4985314 * Z;
g_linear = -0.9692660 * X + 1.8760108 * Y + 0.0415560 * Z;
b_linear = +0.0556434 * X - 0.2040259 * Y + 1.0572252 * Z;
r = r_linear > 0.0031308
? 1.055 * Math.pow(r_linear, (1 / 2.4)) - 0.055
: 12.92 * r_linear;
g = g_linear > 0.0031308
? 1.055 * Math.pow(g_linear, (1 / 2.4)) - 0.055
: 12.92 * g_linear;
b = b_linear > 0.0031308
? 1.055 * Math.pow(b_linear, (1 / 2.4)) - 0.055
: 12.92 * b_linear;
R = r * 255
G = r * 255
B = r * 255
xyz - input CIE XYZ values.rgb - output sRGB values in [0, 255] range.public static void labToXYZ(float[] lab,
float[] xyz)
lab - input CIE L*a*b* values.xyz - output CIE XYZ values.public static void rgbToXYZ(float[] rgb,
float[] xyz)
r = R / 255;
g = G / 255;
b = B / 255;
r_linear = r > 0.04045
? Math.pow((r + 0.055) / 1.055, 2.4)
: r / 12.92;
g_linear = g > 0.04045
? Math.pow((g + 0.055) / 1.055, 2.4)
: g / 12.92;
b_linear = b > 0.04045
? Math.pow((b + 0.055) / 1.055, 2.4)
: b / 12.92;
X = 0.4124564 * r_linear + 0.3575761 * g_linear + 0.1804375 * b_linear;
Y = 0.2126729 * r_linear + 0.7151522 * g_linear + 0.0721750 * b_linear;
Z = 0.0193339 * r_linear + 0.1191920 * g_linear + 0.9503041 * b_linear;
rgb - source sRGB values. Size of array rgb must be at least 3. If size of
array rgb larger than three then only first 3 values are used.xyz - destination CIE XYZ values. Size of array xyz must be at least 3. If
size of array xyz larger than three then only first 3 values are
used.public static void xyzToLab(float[] xyz,
float[] lab)
xyz - source CIE XYZ values. Size of array xyz must be at least 3. If size of
array xyz larger than three then only first 3 values are used.lab - destination CIE L*a*b* values. Size of array lab must be at least 3.
If size of array lab larger than three then only first 3 values are
used.public static VectorProcessor rgbToLabVectorProcessor(ij.process.ColorProcessor cp)
cp - RGB image to be convertedVectorProcessor.public static VectorProcessor rgbToXYZVectorProcessor(ij.process.ColorProcessor cp)
cp - RGB image to be convertedVectorProcessor.public static ij.process.ColorProcessor labToColorProcessor(VectorProcessor vp)
vp - CIE L*a*b* image represented by VectorProcessor.ColorProcessor.public static VectorProcessor labToXYZVectorProcessor(VectorProcessor vp)
vp - L*a*b* image represented by VectorProcessor.VectorProcessor.public static ij.process.ColorProcessor xyzToColorProcessor(VectorProcessor vp)
vp - XYZ image represented by VectorProcessor.ColorProcessor.public static VectorProcessor xyzToLabVectorProcessor(VectorProcessor vp)
vp - XYZ image represented by VectorProcessor.VectorProcessor.public static ij.process.ByteProcessor[] rgbToYCbCr(ij.process.ColorProcessor src,
ProgressListener progressListener)
========================================================================
Y = 16 + 1/256 * ( 65.738 * R + 129.057 * G + 25.064 * B)
Cb = 128 + 1/256 * ( - 37.945 * R - 74.494 * G + 112.439 * B)
Cr = 128 + 1/256 * ( 112.439 * R - 94.154 * G - 18.285 * B)
........................................................................
R, G, B in {0, 1, 2, ..., 255}
Y in {16, 17, ..., 235}
with footroom in {1, 2, ..., 15}
headroom in {236, 237, ..., 254}
sync. in {0, 255}
Cb, Cr in {16, 17, ..., 240}
src - source image.progressListener - progress listener.public static ij.process.ByteProcessor[] rgbToYCbCr(ij.process.ColorProcessor rgb)
rgbToYCbCr(rgb, null).rgb - input image in sRGB color space.rgbToYCbCr(ij.process.ColorProcessor, net.sf.ij_plugins.util.progress.ProgressListener)public static void ycbcrToRGB(byte[] ybr,
byte[] rgb)
======================================================================== R = 1/256 * (298.081952524118 * (Y -16) + 0.001711624973 * (Cb - 128) + 408.582641764512 * (Cr-128)) G = 1/256 * (298.081952524118 * (Y -16) - 100.290891128080 * (Cb - 128) - 208.120396471735 * (Cr-128)) B = 1/256 * (298.081952524118 * (Y -16) + 516.412147108167 * (Cb - 128) - 0.000466679809 * (Cr-128))
ybr - source Y, Cb, and Cr (cannot ne null).rgb - destination RGB (cannot be null).public static ij.process.ColorProcessor ycbcrToRGB(ij.process.ByteProcessor[] ybr,
ProgressListener progressListener)
======================================================================== R = 1/256 * (298.081952524118 * (Y -16) + 0.001711624973 * (Cb - 128) + 408.582641764512 * (Cr-128)) G = 1/256 * (298.081952524118 * (Y -16) - 100.290891128080 * (Cb - 128) - 208.120396471735 * (Cr-128)) B = 1/256 * (298.081952524118 * (Y -16) + 516.412147108167 * (Cb - 128) - 0.000466679809 * (Cr-128))
ybr - source image, array of color bands: Y, Cb, Cr, respectively.progressListener - progress listener, can be null.public static ij.process.ColorProcessor ycbcrToRGB(ij.process.ByteProcessor[] ybr)
ycbcrToRGB(ybr, null).ybr - array of ByteProcessor representing color planes: Y, Cb, and Cr.ycbcrToRGB(ij.process.ByteProcessor[], net.sf.ij_plugins.util.progress.ProgressListener)