skimage2.color.convert_colorspace#

skimage2.color.convert_colorspace(arr, fromspace, tospace, *, channel_axis=-1)[source]#

Convert an image array to a new color space.

Valid color spaces are:

‘RGB’, ‘HSV’, ‘RGB CIE’, ‘XYZ’, ‘YUV’, ‘YIQ’, ‘YPbPr’, ‘YCbCr’, ‘YDbDr’

Parameters:
arrarray_like of shape (…, C=3, …)

The image to convert. By default, the final dimension denotes channels.

fromspacestr

The color space to convert from. Can be specified in lower case.

tospacestr

The color space to convert to. Can be specified in lower case.

channel_axisint, optional

This parameter indicates which axis of the array corresponds to channels.

Added in version 0.19: channel_axis was added in 0.19.

Returns:
outndarray of shape (…, C=3, …)

The converted image. Same dimensions as input.

Raises:
ValueError

If fromspace is not a valid color space

ValueError

If tospace is not a valid color space

Notes

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

Examples

>>> from _skimage2 import data
>>> img = data.astronaut()
>>> img_hsv = convert_colorspace(img, 'RGB', 'HSV')