Image.colorspace#
- Image.colorspace(dst: str, src: str | None = None, dtype: Any = None) Self[source]#
Transform a color image between color representations
- Parameters:
- Raises:
ValueError – integer data in, or asked for in, a color space with natural units
- Returns:
color image in new colorspace
- Return type:
Color space names (synonyms listed on the same line) are:
Color space name
Option string(s)
grey scale
‘grey’, ‘gray’
RGB (red/green/blue)
‘rgb’
BGR (blue/green/red)
‘bgr’
CIE XYZ
‘xyz’, ‘xyz_709’
YCrCb
‘ycrcb’
HSV (hue/sat/value)
‘hsv’
HLS (hue/lightness/sat)
‘hls’
CIE L*a*b*
‘lab’, ‘l*a*b*’
CIE L*u*v*
‘luv’, ‘l*u*v*’
Examples
>>> from machinevisiontoolbox import Image >>> im = Image.Read('flowers1.png') >>> im.colorspace('hsv') Image(size=(640, 426), dtype=float32, nplanes=3, colororder=h:s:v)
Note
RGB images are assumed to be linear, or gamma decoded.
Note
Integer images span 0 to the maximum value of their type, and float images span 0 to 1. This holds for the RGB, BGR, grey and YCrCb color spaces.
HSV, HLS, CIE XYZ, L*a*b* and L*u*v* are always floating point and have their natural units: hue is in degrees, L* is 0 to 100, and a* and b* can be negative. An integer image converted to one of these has type float32. An integer type cannot be the source or destination.
Changed in version 2.5.0: Added the
dtypeargument. The result has the type of the image, as before, except as noted above. Previously an 8-bit image converted to HSV, L*a*b* or XYZ had OpenCV’s 8-bit encoding of those spaces.References
P. Corke, Robotics, Vision & Control for Python, Springer, 2023, Section 10.2.7, 10.4.1.
See also