Navigation

Documentation Home

 

Contents

Version

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 grey-level image.
skimage.color.hsv2rgb(hsv) HSV to RGB color 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.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.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

>>> import os
>>> from skimage import data_dir
>>> from skimage.io import imread
>>> lena = imread(os.path.join(data_dir, 'lena.png'))
>>> lena_hsv = convert_colorspace(lena, 'RGB', 'HSV')

gray2rgb

skimage.color.gray2rgb(image)

Create an RGB representation of a grey-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 [R11].

References

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

Examples

>>> import os
>>> from skimage import data_dir
>>> from skimage.io import imread
>>> lena = imread(os.path.join(data_dir, 'lena.png'))
>>> lena_hsv = rgb2hsv(lena)
>>> lena_rgb = hsv2rgb(lena_hsv)

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 rgb2grey 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

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

Examples

>>> import os
>>> from skimage import data_dir
>>> from skimage.io import imread
>>> from skimage.color import rgb2grey
>>> lena = imread(os.path.join(data_dir, 'lena.png'))
>>> lena_grey = rgb2grey(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 rgb2grey 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

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

Examples

>>> import os
>>> from skimage import data_dir
>>> from skimage.io import imread
>>> from skimage.color import rgb2grey
>>> lena = imread(os.path.join(data_dir, 'lena.png'))
>>> lena_grey = rgb2grey(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 [R14].

References

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

Examples

>>> import os
>>> from skimage import data_dir
>>> from skimage.io import imread
>>> lena = imread(os.path.join(data_dir, 'lena.png'))
>>> lena_hsv = color.rgb2hsv(lena)

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

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

Examples

>>> import os
>>> from skimage import data_dir
>>> from skimage.io import imread
>>> from skimage.color import rgb2rgbcie
>>> lena = imread(os.path.join(data_dir, 'lena.png'))
>>> 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

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

Examples

>>> import os
>>> from skimage import data_dir
>>> from skimage.io import imread
>>> lena = imread(os.path.join(data_dir, 'lena.png'))
>>> 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

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

Examples

>>> import os
>>> from skimage import data_dir
>>> from skimage.io import imread
>>> from skimage.color import rgb2rgbcie, rgbcie2rgb
>>> lena = imread(os.path.join(data_dir, 'lena.png'))
>>> lena_rgbcie = rgb2rgbcie(lena)
>>> lena_rgb = rgbcie2rgb(lena_hsv)

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

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

Examples

>>> import os
>>> from skimage import data_dir
>>> from skimage.io import imread
>>> from skimage.color import rgb2xyz, xyz2rgb
>>> lena = imread(os.path.join(data_dir, 'lena.png'))
>>> lena_xyz = rgb2xyz(lena)
>>> lena_rgb = xyz2rgb(lena_hsv)