Module: color

skimage.color.convert_colorspace(arr, ...) Convert an image array to a new color space.
skimage.color.gray2rgb(image) Create an RGB representation of a gray-level image.
skimage.color.hsv2rgb(hsv) HSV to RGB color space conversion.
skimage.color.is_gray(image) Test whether the image is gray (i.e.
skimage.color.is_rgb(image) Test whether the image is RGB or RGBA.
skimage.color.lab2rgb(lab) Lab to RGB color space conversion.
skimage.color.lab2xyz(lab) CIE-LAB to XYZcolor space conversion.
skimage.color.rgb2gray(rgb) Compute luminance of an RGB image.
skimage.color.rgb2grey(rgb) Compute luminance of an RGB image.
skimage.color.rgb2hsv(rgb) RGB to HSV color space conversion.
skimage.color.rgb2lab(rgb) RGB to lab color space conversion.
skimage.color.rgb2rgbcie(rgb) RGB to RGB CIE color space conversion.
skimage.color.rgb2xyz(rgb) RGB to XYZ color space conversion.
skimage.color.rgbcie2rgb(rgbcie) RGB CIE to RGB color space conversion.
skimage.color.xyz2lab(xyz) XYZ to CIE-LAB color space conversion.
skimage.color.xyz2rgb(xyz) XYZ to RGB color space conversion.

convert_colorspace

skimage.color.convert_colorspace(arr, fromspace, tospace)

Convert an image array to a new color space.

Parameters :

arr : array_like

The image to convert.

fromspace : str

The color space to convert from. Valid color space strings are [‘RGB’, ‘HSV’, ‘RGB CIE’, ‘XYZ’]. Value may also be specified as lower case.

tospace : str

The color space to convert to. Valid color space strings are [‘RGB’, ‘HSV’, ‘RGB CIE’, ‘XYZ’]. Value may also be specified as lower case.

Returns :

newarr : ndarray

The converted image.

Notes

Conversion occurs through the “central” RGB color space, i.e. conversion from XYZ to HSV is implemented as XYZ -> RGB -> HSV instead of directly.

Examples

>>> from skimage import data
>>> lena = data.lena()
>>> lena_hsv = convert_colorspace(lena, 'RGB', 'HSV')

gray2rgb

skimage.color.gray2rgb(image)

Create an RGB representation of a gray-level image.

Parameters :

image : array_like

Input image of shape (M, N).

Returns :

rgb : ndarray

RGB image of shape (M, N, 3).

Raises :

ValueError :

If the input is not 2-dimensional.

hsv2rgb

skimage.color.hsv2rgb(hsv)

HSV to RGB color space conversion.

Parameters :

hsv : array_like

The image in HSV format, in a 3-D array of shape (.., .., 3).

Returns :

out : ndarray

The image in RGB format, in a 3-D array of shape (.., .., 3).

Raises :

ValueError :

If hsv is not a 3-D array of shape (.., .., 3).

Notes

The conversion assumes an input data range of [0, 1] for all color components.

Conversion between RGB and HSV color spaces results in some loss of precision, due to integer arithmetic and rounding [R15].

References

[R15](1, 2) http://en.wikipedia.org/wiki/HSL_and_HSV

Examples

>>> from skimage import data
>>> lena = data.lena()
>>> lena_hsv = rgb2hsv(lena)
>>> lena_rgb = hsv2rgb(lena_hsv)

is_gray

skimage.color.is_gray(image)

Test whether the image is gray (i.e. has only one color band).

Parameters :

image : ndarray

Input image.

is_rgb

skimage.color.is_rgb(image)

Test whether the image is RGB or RGBA.

Parameters :

image : ndarray

Input image.

lab2rgb

skimage.color.lab2rgb(lab)

Lab to RGB color space conversion.

Parameters :

rgb : array_like

The image in Lab format, in a 3-D array of shape (.., .., 3).

Returns :

out : ndarray

The image in RGB format, in a 3-D array of shape (.., .., 3).

Raises :

ValueError :

If lab is not a 3-D array of shape (.., .., 3).

Notes

This function uses lab2xyz and xyz2rgb.

lab2xyz

skimage.color.lab2xyz(lab)

CIE-LAB to XYZcolor space conversion.

Parameters :

lab : array_like

The image in lab format, in a 3-D array of shape (.., .., 3).

Returns :

out : ndarray

The image in XYZ format, in a 3-D array of shape (.., .., 3).

Raises :

ValueError :

If lab is not a 3-D array of shape (.., .., 3).

Notes

Observer= 2A, Illuminant= D65 CIE XYZ tristimulus values x_ref = 95.047, y_ref = 100., z_ref = 108.883

References

[R16]http://www.easyrgb.com/index.php?X=MATH&H=07#text7
[R17]http://en.wikipedia.org/wiki/Lab_color_space

rgb2gray

skimage.color.rgb2gray(rgb)

Compute luminance of an RGB image.

Parameters :

rgb : array_like

The image in RGB format, in a 3-D array of shape (.., .., 3), or in RGBA format with shape (.., .., 4).

Returns :

out : ndarray

The luminance image, a 2-D array.

Raises :

ValueError :

If rgb2gray is not a 3-D array of shape (.., .., 3) or (.., .., 4).

Notes

The weights used in this conversion are calibrated for contemporary CRT phosphors:

Y = 0.2125 R + 0.7154 G + 0.0721 B

If there is an alpha channel present, it is ignored.

References

[R18]http://www.poynton.com/PDFs/ColorFAQ.pdf

Examples

>>> from skimage.color import rgb2gray
>>> from skimage import data
>>> lena = data.lena()
>>> lena_gray = rgb2gray(lena)

rgb2grey

skimage.color.rgb2grey(rgb)

Compute luminance of an RGB image.

Parameters :

rgb : array_like

The image in RGB format, in a 3-D array of shape (.., .., 3), or in RGBA format with shape (.., .., 4).

Returns :

out : ndarray

The luminance image, a 2-D array.

Raises :

ValueError :

If rgb2gray is not a 3-D array of shape (.., .., 3) or (.., .., 4).

Notes

The weights used in this conversion are calibrated for contemporary CRT phosphors:

Y = 0.2125 R + 0.7154 G + 0.0721 B

If there is an alpha channel present, it is ignored.

References

[R19]http://www.poynton.com/PDFs/ColorFAQ.pdf

Examples

>>> from skimage.color import rgb2gray
>>> from skimage import data
>>> lena = data.lena()
>>> lena_gray = rgb2gray(lena)

rgb2hsv

skimage.color.rgb2hsv(rgb)

RGB to HSV color space conversion.

Parameters :

rgb : array_like

The image in RGB format, in a 3-D array of shape (.., .., 3).

Returns :

out : ndarray

The image in HSV format, in a 3-D array of shape (.., .., 3).

Raises :

ValueError :

If rgb is not a 3-D array of shape (.., .., 3).

Notes

The conversion assumes an input data range of [0, 1] for all color components.

Conversion between RGB and HSV color spaces results in some loss of precision, due to integer arithmetic and rounding [R20].

References

[R20](1, 2) http://en.wikipedia.org/wiki/HSL_and_HSV

Examples

>>> from skimage import color
>>> from skimage import data
>>> lena = data.lena()
>>> lena_hsv = color.rgb2hsv(lena)

rgb2lab

skimage.color.rgb2lab(rgb)

RGB to lab color space conversion.

Parameters :

rgb : array_like

The image in RGB format, in a 3-D array of shape (.., .., 3).

Returns :

out : ndarray

The image in Lab format, in a 3-D array of shape (.., .., 3).

Raises :

ValueError :

If rgb is not a 3-D array of shape (.., .., 3).

Notes

This function uses rgb2xyz and xyz2lab.

rgb2rgbcie

skimage.color.rgb2rgbcie(rgb)

RGB to RGB CIE color space conversion.

Parameters :

rgb : array_like

The image in RGB format, in a 3-D array of shape (.., .., 3).

Returns :

out : ndarray

The image in RGB CIE format, in a 3-D array of shape (.., .., 3).

Raises :

ValueError :

If rgb is not a 3-D array of shape (.., .., 3).

References

[R21]http://en.wikipedia.org/wiki/CIE_1931_color_space

Examples

>>> from skimage import data
>>> from skimage.color import rgb2rgbcie
>>> lena = data.lena()
>>> lena_rgbcie = rgb2rgbcie(lena)

rgb2xyz

skimage.color.rgb2xyz(rgb)

RGB to XYZ color space conversion.

Parameters :

rgb : array_like

The image in RGB format, in a 3-D array of shape (.., .., 3).

Returns :

out : ndarray

The image in XYZ format, in a 3-D array of shape (.., .., 3).

Raises :

ValueError :

If rgb is not a 3-D array of shape (.., .., 3).

Notes

The CIE XYZ color space is derived from the CIE RGB color space. Note however that this function converts from sRGB.

References

[R22]http://en.wikipedia.org/wiki/CIE_1931_color_space

Examples

>>> from skimage import data
>>> lena = data.lena()
>>> lena_xyz = rgb2xyz(lena)

rgbcie2rgb

skimage.color.rgbcie2rgb(rgbcie)

RGB CIE to RGB color space conversion.

Parameters :

rgbcie : array_like

The image in RGB CIE format, in a 3-D array of shape (.., .., 3).

Returns :

out : ndarray

The image in RGB format, in a 3-D array of shape (.., .., 3).

Raises :

ValueError :

If rgbcie is not a 3-D array of shape (.., .., 3).

References

[R23]http://en.wikipedia.org/wiki/CIE_1931_color_space

Examples

>>> from skimage import data
>>> from skimage.color import rgb2rgbcie, rgbcie2rgb
>>> lena = data.lena()
>>> lena_rgbcie = rgb2rgbcie(lena)
>>> lena_rgb = rgbcie2rgb(lena_rgbcie)

xyz2lab

skimage.color.xyz2lab(xyz)

XYZ to CIE-LAB color space conversion.

Parameters :

xyz : array_like

The image in XYZ format, in a 3-D array of shape (.., .., 3).

Returns :

out : ndarray

The image in CIE-LAB format, in a 3-D array of shape (.., .., 3).

Raises :

ValueError :

If xyz is not a 3-D array of shape (.., .., 3).

Notes

Observer= 2A, Illuminant= D65 CIE XYZ tristimulus values x_ref = 95.047, y_ref = 100., z_ref = 108.883

References

[R24]http://www.easyrgb.com/index.php?X=MATH&H=07#text7
[R25]http://en.wikipedia.org/wiki/Lab_color_space

Examples

>>> from skimage import data
>>> from skimage.color import rgb2xyz, xyz2lab
>>> lena = data.lena()
>>> lena_xyz = rgb2xyz(lena)
>>> lena_lab = xyz2lab(lena_xyz)

xyz2rgb

skimage.color.xyz2rgb(xyz)

XYZ to RGB color space conversion.

Parameters :

xyz : array_like

The image in XYZ format, in a 3-D array of shape (.., .., 3).

Returns :

out : ndarray

The image in RGB format, in a 3-D array of shape (.., .., 3).

Raises :

ValueError :

If xyz is not a 3-D array of shape (.., .., 3).

Notes

The CIE XYZ color space is derived from the CIE RGB color space. Note however that this function converts to sRGB.

References

[R26]http://en.wikipedia.org/wiki/CIE_1931_color_space

Examples

>>> from skimage import data
>>> from skimage.color import rgb2xyz, xyz2rgb
>>> lena = data.lena()
>>> lena_xyz = rgb2xyz(lena)
>>> lena_rgb = xyz2rgb(lena_xyz)