DCMTK Version 3.7.1
OFFIS DICOM Toolkit
Loading...
Searching...
No Matches
IODCIELabUtil Class Reference

Class supporting color space conversions from and to CIELab. More...

Static Public Member Functions

static void dicomLab2RGB (double &R, double &G, double &B, double LDicom, double aDicom, double bDicom)
 Convert CIELab color representation as found in DICOM to sRGB value representation.
static void dicomLab2RGB (Uint8 &R, Uint8 &G, Uint8 &B, Uint16 LDicom, Uint16 aDicom, Uint16 bDicom)
 Convert CIELab color representation as found in DICOM to 8 bit sRGB value representation.
static void rgb2DicomLab (double &LDicom, double &aDicom, double &bDicom, double R, double G, double B)
 Convert sRGB color representation to CIELab color representation as found in DICOM.
static void rgb2DicomLab (Uint16 &LDicom, Uint16 &aDicom, Uint16 &bDicom, Uint8 R, Uint8 G, Uint8 B)
 Convert 8 bit sRGB color representation to CIELab color representation as found in DICOM.
static void dicomlab2Lab (double &L, double &a, double &b, double LDicom, double aDicom, double bDicom)
 Convert CIELab color representation as found in DICOM to CIELab representation.
static void lab2DicomLab (double &LDicom, double &aDicom, double &bDicom, double L, double a, double b)
 Convert CIELab color representation to CIELab color representation found in DICOM.
static void rgb2Lab (double &L, double &a, double &b, double R, double G, double B)
 Convert sRGB color representation to CIELab representation (relative to the D50 white point, i.e.
static void rgb2Xyz (double &X, double &Y, double &Z, double R, double G, double B)
 Convert sRGB color representation to CIE XYZ representation relative to the D50 white point (ICC PCS XYZ), i.e.
static void xyz2Lab (double &L, double &a, double &b, double X, double Y, double Z)
 Convert CIE XYZ color representation (relative to D50) to CIELab representation (relative to D50).
static void lab2Rgb (double &R, double &G, double &B, double L, double a, double b)
 Convert CIELab color representation (relative to D50) to sRGB representation.
static void lab2Xyz (double &X, double &Y, double &Z, double L, double a, double b)
 Convert CIELab color representation (relative to D50) to CIE XYZ representation (relative to D50).
static void xyz2Rgb (double &R, double &G, double &B, double X, double Y, double Z)
 Convert CIE XYZ color representation (relative to D50, ICC PCS XYZ) to sRGB representation, i.e.

Static Public Attributes

static const double D50_WHITEPOINT_X
 D50 white point X component (ICC PCS illuminant, CIELab reference white).
static const double D50_WHITEPOINT_Y
 D50 white point Y component (ICC PCS illuminant, CIELab reference white).
static const double D50_WHITEPOINT_Z
 D50 white point Z component (ICC PCS illuminant, CIELab reference white).
static const double D65_WHITEPOINT_X
 D65 white point X component (native white point of sRGB).
static const double D65_WHITEPOINT_Y
 D65 white point Y component (native white point of sRGB).
static const double D65_WHITEPOINT_Z
 D65 white point Z component (native white point of sRGB).

Static Protected Member Functions

static double gammaCorrection (double n)
 Perform sRGB gamma encoding, transforms linear R to R'.
static double invGammaCorrection (double n)
 Perform inverse sRGB gamma encoding, transforms R' to linear R.
static double labf (double n)
 CIE L*a*b* f function (used to convert XYZ to L*a*b*).
static double labfInv (double n)
 CIE L*a*b* inverse f function.
static double clamp01 (double n)
 Clamp a value to the range 0 <= value <= 1.
static double roundClamp (double n, double max)
 Round a value to the nearest integer and clamp it to the range 0 <= value <= max.

Detailed Description

Class supporting color space conversions from and to CIELab.

In some IODs DICOM stores CIELab color values (e.g. Recommended Display CIELab Value) which must often be converted to RGB for display or other purposes. This is supported by the functions dicomLab2RGB() and rgb2DicomLab(). The CIELab value range in DICOM is [0,65535] for all three values. The RGB value range in this class is [0,1] (or [0,255] for the 8 bit integer variants). Further functions are available in order to convert between RGB, "normal" CIELab value range as well as CIEXYZ. The class uses double floating point precision for calculations.

DICOM (part 3, C.10.7.1.1) encodes CIELab values in the same way as the ICC Profile Connection Space (PCS), i.e. the CIELab values are relative to the D50 illuminant. The RGB values handled by this class are sRGB values, whose native white point is D65. This class therefore converts sRGB to linear RGB, to CIEXYZ (D65), chromatically adapts the CIEXYZ values to D50 using the linear Bradford transform, and finally computes CIELab relative to the D50 white point (and vice versa). All CIEXYZ values exposed by this class are D50 (PCS) values. The matrices and constants used are those of the CSS Color Module Level 4 sample code (https://www.w3.org/TR/css-color-4/#color-conversion-code), so that results are consistent with other DICOM implementations following the same approach.

Note that up to and including DCMTK 3.7.0 the CIELab values computed by this class were relative to D65, i.e. no chromatic adaptation to the PCS illuminant took place. For neutral (gray) colors the results are the same, for chromatic colors the a* and b* values differ slightly.

Member Function Documentation

◆ clamp01()

double IODCIELabUtil::clamp01 ( double n)
staticprotected

Clamp a value to the range 0 <= value <= 1.

Parameters
nThe value to clamp
Returns
The clamped value

◆ dicomlab2Lab()

void IODCIELabUtil::dicomlab2Lab ( double & L,
double & a,
double & b,
double LDicom,
double aDicom,
double bDicom )
static

Convert CIELab color representation as found in DICOM to CIELab representation.

See DICOM part 3 for details.

Parameters
LOutput CIELab luminance component with 0 <= L <= 100
aOutput CIELab "a" component (red<->green) with -128 <= a <= 127
bOutput CIELab "b" component (blue<->yellow) with -128 <= b <= 127
LDicomInput CIELab luminance component with 0 <= L <= 65535 as found in DICOM
aDicomInput CIELab "a" component (red<->green) with 0 <= a <= 65535 as found in DICOM
bDicomInput CIELab "b" component (blue<->yellow) with 0 <= b <= 65535 as found in DICOM

◆ dicomLab2RGB() [1/2]

void IODCIELabUtil::dicomLab2RGB ( double & R,
double & G,
double & B,
double LDicom,
double aDicom,
double bDicom )
static

Convert CIELab color representation as found in DICOM to sRGB value representation.

See DICOM part 3 for details. Colors outside the sRGB gamut are clipped, i.e. the resulting R, G and B values are always within the range 0 <= value <= 1.

Parameters
ROutput sRGB "R" component (red) with 0 <= R <= 1
GOutput sRGB "G" component (green) with 0 <= G <= 1
BOutput sRGB "B" component (blue) with 0 <= B <= 1
LDicomInput DICOM CIELab luminance component with 0 <= L <= 65535
aDicomInput DICOM CIELab "a" component (red<->green) with 0 <= a <= 65535
bDicomInput DICOM CIELab "b" component (blue<->yellow) with 0 <= b <= 65535

◆ dicomLab2RGB() [2/2]

void IODCIELabUtil::dicomLab2RGB ( Uint8 & R,
Uint8 & G,
Uint8 & B,
Uint16 LDicom,
Uint16 aDicom,
Uint16 bDicom )
static

Convert CIELab color representation as found in DICOM to 8 bit sRGB value representation.

This is a convenience variant of dicomLab2RGB(double&, double&, double&, double, double, double) that rounds the result to the nearest integer and clamps it to the range 0 <= value <= 255.

Parameters
ROutput sRGB "R" component (red) with 0 <= R <= 255
GOutput sRGB "G" component (green) with 0 <= G <= 255
BOutput sRGB "B" component (blue) with 0 <= B <= 255
LDicomInput DICOM CIELab luminance component with 0 <= L <= 65535
aDicomInput DICOM CIELab "a" component (red<->green) with 0 <= a <= 65535
bDicomInput DICOM CIELab "b" component (blue<->yellow) with 0 <= b <= 65535

◆ gammaCorrection()

double IODCIELabUtil::gammaCorrection ( double n)
staticprotected

Perform sRGB gamma encoding, transforms linear R to R'.

Parameters
nThe value to encode, 0 <= n <= 1
Returns
The gamma-encoded value

◆ invGammaCorrection()

double IODCIELabUtil::invGammaCorrection ( double n)
staticprotected

Perform inverse sRGB gamma encoding, transforms R' to linear R.

Parameters
nThe value to decode, 0 <= n <= 1
Returns
The linear value

◆ lab2DicomLab()

void IODCIELabUtil::lab2DicomLab ( double & LDicom,
double & aDicom,
double & bDicom,
double L,
double a,
double b )
static

Convert CIELab color representation to CIELab color representation found in DICOM.

See DICOM part 3 for details.

Parameters
LDicomOutput CIELab luminance component with 0 <= L <= 65535 as found in DICOM
aDicomOutput CIELab "a" component (red<->green) with 0 <= a <= 65535 as found in DICOM
bDicomOutput CIELab "b" component (blue<->yellow) with 0 <= b <= 65535 as found in DICOM
LInput CIELab luminance component with 0 <= L <= 100
aInput CIELab "a" component (red<->green) with -128 <= a <= 127
bInput CIELab "b" component (blue<->yellow) with -128 <= b <= 127

◆ lab2Rgb()

void IODCIELabUtil::lab2Rgb ( double & R,
double & G,
double & B,
double L,
double a,
double b )
static

Convert CIELab color representation (relative to D50) to sRGB representation.

Colors outside the sRGB gamut are clipped, i.e. the resulting R, G and B values are always within the range 0 <= value <= 1.

Parameters
ROutput sRGB "R" component (red) with 0 <= R <= 1
GOutput sRGB "G" component (green) with 0 <= G <= 1
BOutput sRGB "B" component (blue) with 0 <= B <= 1
LInput CIELab luminance component with 0 <= L <= 100
aInput CIELab "a" component (red<->green) with -128 <= a <= 127
bInput CIELab "b" component (blue<->yellow) with -128 <= b <= 127

◆ lab2Xyz()

void IODCIELabUtil::lab2Xyz ( double & X,
double & Y,
double & Z,
double L,
double a,
double b )
static

Convert CIELab color representation (relative to D50) to CIE XYZ representation (relative to D50).

Parameters
XOutput CIE XYZ "X" component with 0 <= X <= D50_WHITEPOINT_X
YOutput CIE XYZ "Y" component with 0 <= Y <= 1
ZOutput CIE XYZ "Z" component with 0 <= Z <= D50_WHITEPOINT_Z
LInput CIELab luminance component with 0 <= L <= 100
aInput CIELab "a" component (red<->green) with -128 <= a <= 127
bInput CIELab "b" component (blue<->yellow) with -128 <= b <= 127

◆ labf()

double IODCIELabUtil::labf ( double n)
staticprotected

CIE L*a*b* f function (used to convert XYZ to L*a*b*).

Parameters
nvalue to convert
Returns
The converted value

◆ labfInv()

double IODCIELabUtil::labfInv ( double n)
staticprotected

CIE L*a*b* inverse f function.

Parameters
nThe value to compute the inverse for
Returns
The resulting inverse

◆ rgb2DicomLab() [1/2]

void IODCIELabUtil::rgb2DicomLab ( double & LDicom,
double & aDicom,
double & bDicom,
double R,
double G,
double B )
static

Convert sRGB color representation to CIELab color representation as found in DICOM.

See DICOM part 3 for details.

Parameters
LDicomOutput CIELab luminance component with 0 <= L <= 65535 as found in DICOM
aDicomOutput CIELab "a" component (red<->green) with 0 <= a <= 65535 as found in DICOM
bDicomOutput CIELab "b" component (blue<->yellow) with 0 <= b <= 65535 as found in DICOM
RInput sRGB "R" component (red) with 0 <= R <= 1
GInput sRGB "G" component (green) with 0 <= G <= 1
BInput sRGB "B" component (blue) with 0 <= B <= 1

◆ rgb2DicomLab() [2/2]

void IODCIELabUtil::rgb2DicomLab ( Uint16 & LDicom,
Uint16 & aDicom,
Uint16 & bDicom,
Uint8 R,
Uint8 G,
Uint8 B )
static

Convert 8 bit sRGB color representation to CIELab color representation as found in DICOM.

This is a convenience variant of rgb2DicomLab(double&, double&, double&, double, double, double) that rounds the result to the nearest integer and clamps it to the range 0 <= value <= 65535.

Parameters
LDicomOutput CIELab luminance component with 0 <= L <= 65535 as found in DICOM
aDicomOutput CIELab "a" component (red<->green) with 0 <= a <= 65535 as found in DICOM
bDicomOutput CIELab "b" component (blue<->yellow) with 0 <= b <= 65535 as found in DICOM
RInput sRGB "R" component (red) with 0 <= R <= 255
GInput sRGB "G" component (green) with 0 <= G <= 255
BInput sRGB "B" component (blue) with 0 <= B <= 255

◆ rgb2Lab()

void IODCIELabUtil::rgb2Lab ( double & L,
double & a,
double & b,
double R,
double G,
double B )
static

Convert sRGB color representation to CIELab representation (relative to the D50 white point, i.e.

ICC PCS CIELab)

Parameters
LOutput CIELab luminance component with 0 <= L <= 100
aOutput CIELab "a" component (red<->green) with -128 <= a <= 127
bOutput CIELab "b" component (blue<->yellow) with -128 <= b <= 127
RInput sRGB "R" component (red) with 0 <= R <= 1
GInput sRGB "G" component (green) with 0 <= G <= 1
BInput sRGB "B" component (blue) with 0 <= B <= 1

◆ rgb2Xyz()

void IODCIELabUtil::rgb2Xyz ( double & X,
double & Y,
double & Z,
double R,
double G,
double B )
static

Convert sRGB color representation to CIE XYZ representation relative to the D50 white point (ICC PCS XYZ), i.e.

the sRGB values are linearized, converted to CIE XYZ (D65) and then chromatically adapted to D50 using the linear Bradford transform.

Parameters
XOutput CIE XYZ "X" component with 0 <= X <= D50_WHITEPOINT_X
YOutput CIE XYZ "Y" component with 0 <= Y <= 1
ZOutput CIE XYZ "Z" component with 0 <= Z <= D50_WHITEPOINT_Z
RInput sRGB "R" component (red) with 0 <= R <= 1
GInput sRGB "G" component (green) with 0 <= G <= 1
BInput sRGB "B" component (blue) with 0 <= B <= 1

◆ roundClamp()

double IODCIELabUtil::roundClamp ( double n,
double max )
staticprotected

Round a value to the nearest integer and clamp it to the range 0 <= value <= max.

Parameters
nThe value to round and clamp
maxThe maximum permitted value
Returns
The rounded and clamped value

◆ xyz2Lab()

void IODCIELabUtil::xyz2Lab ( double & L,
double & a,
double & b,
double X,
double Y,
double Z )
static

Convert CIE XYZ color representation (relative to D50) to CIELab representation (relative to D50).

Parameters
LOutput CIELab luminance component with 0 <= L <= 100
aOutput CIELab "a" component (red<->green) with -128 <= a <= 127
bOutput CIELab "b" component (blue<->yellow) with -128 <= b <= 127
XInput CIE XYZ "X" component with 0 <= X <= D50_WHITEPOINT_X
YInput CIE XYZ "Y" component with 0 <= Y <= 1
ZInput CIE XYZ "Z" component with 0 <= Z <= D50_WHITEPOINT_Z

◆ xyz2Rgb()

void IODCIELabUtil::xyz2Rgb ( double & R,
double & G,
double & B,
double X,
double Y,
double Z )
static

Convert CIE XYZ color representation (relative to D50, ICC PCS XYZ) to sRGB representation, i.e.

the XYZ values are chromatically adapted from D50 to D65 using the linear Bradford transform, converted to linear RGB and finally gamma-encoded. Colors outside the sRGB gamut are clipped, i.e. the resulting R, G and B values are always within the range 0 <= value <= 1.

Parameters
ROutput sRGB "R" component (red) with 0 <= R <= 1
GOutput sRGB "G" component (green) with 0 <= G <= 1
BOutput sRGB "B" component (blue) with 0 <= B <= 1
XInput CIE XYZ "X" component with 0 <= X <= D50_WHITEPOINT_X
YInput CIE XYZ "Y" component with 0 <= Y <= 1
ZInput CIE XYZ "Z" component with 0 <= Z <= D50_WHITEPOINT_Z

The documentation for this class was generated from the following file:


Generated on for DCMTK Version 3.7.1 by Doxygen 1.18.0