Color Spaces Module
The color_spaces module provides functions for converting between different color spaces commonly used in computer vision and image processing.
Color space conversion functions.
This module provides functions for converting between different color spaces commonly used in computer vision and image processing.
- Functions:
cvt_color, cvtColor: Generic color space conversion function.
rgb2bgr, bgr2rgb: Convert between RGB and BGR color spaces.
rgba2bgra, bgra2rgba: Convert between RGBA and BGRA color spaces.
rgb2gray, bgr2gray: Convert color images to grayscale.
gray2rgb, gray2bgr: Convert grayscale images to color.
gray2rgba, gray2bgra: Convert grayscale images to color with alpha channel.
bgr2hsv, rgb2hsv: Convert color images to HSV color space.
hsv2bgr, hsv2rgb: Convert HSV images to color.
rgb, bgr: Aliases for rgb2bgr and bgr2rgb.
rgba, bgra: Aliases for rgba2bgra and bgra2rgba.
- cv3.color_spaces.cvt_color(img, code)[source]
Convert image between different color spaces.
- Parameters:
img (numpy.ndarray) – Input image.
code (int) – Color space conversion code (e.g., cv2.COLOR_RGB2BGR).
- Returns:
Image in the target color space.
- Return type:
numpy.ndarray
- Raises:
ValueError – If trying to convert a non-grayscale image to RGB/RGBA.
- cv3.color_spaces.cvtColor(img, code)
Alias for
cvt_color().
- cv3.color_spaces.rgb2bgr(img)[source]
Convert image from RGB to BGR color space.
- Parameters:
img (numpy.ndarray) – Input image in RGB format.
- Returns:
Image in BGR format.
- Return type:
numpy.ndarray
- cv3.color_spaces.bgr2rgb(img)[source]
Convert image from BGR to RGB color space.
- Parameters:
img (numpy.ndarray) – Input image in BGR format.
- Returns:
Image in RGB format.
- Return type:
numpy.ndarray
- cv3.color_spaces.rgba2bgra(img)[source]
Convert image from RGBA to BGRA color space.
- Parameters:
img (numpy.ndarray) – Input image in RGBA format.
- Returns:
Image in BGRA format.
- Return type:
numpy.ndarray
- cv3.color_spaces.bgra2rgba(img)[source]
Convert image from BGRA to RGBA color space.
- Parameters:
img (numpy.ndarray) – Input image in BGRA format.
- Returns:
Image in RGBA format.
- Return type:
numpy.ndarray
- cv3.color_spaces.rgb2gray(img)[source]
Convert image from RGB to grayscale.
- Parameters:
img (numpy.ndarray) – Input image in RGB format.
- Returns:
Grayscale image.
- Return type:
numpy.ndarray
- cv3.color_spaces.bgr2gray(img)[source]
Convert image from BGR to grayscale.
- Parameters:
img (numpy.ndarray) – Input image in BGR format.
- Returns:
Grayscale image.
- Return type:
numpy.ndarray
- cv3.color_spaces.gray2rgb(img)[source]
Convert grayscale image to RGB.
- Parameters:
img (numpy.ndarray) – Input grayscale image.
- Returns:
Image in RGB format.
- Return type:
numpy.ndarray
- Raises:
ValueError – If input image is not grayscale.
- cv3.color_spaces.gray2bgr(img)[source]
Convert grayscale image to BGR.
- Parameters:
img (numpy.ndarray) – Input grayscale image.
- Returns:
Image in BGR format.
- Return type:
numpy.ndarray
- Raises:
ValueError – If input image is not grayscale.
- cv3.color_spaces.gray2rgba(img)[source]
Convert grayscale image to RGBA.
- Parameters:
img (numpy.ndarray) – Input grayscale image.
- Returns:
Image in RGBA format.
- Return type:
numpy.ndarray
- Raises:
ValueError – If input image is not grayscale.
- cv3.color_spaces.gray2bgra(img)[source]
Convert grayscale image to BGRA.
- Parameters:
img (numpy.ndarray) – Input grayscale image.
- Returns:
Image in BGRA format.
- Return type:
numpy.ndarray
- Raises:
ValueError – If input image is not grayscale.
- cv3.color_spaces.bgr2hsv(img)[source]
Convert image from BGR to HSV color space.
- Parameters:
img (numpy.ndarray) – Input image in BGR format.
- Returns:
Image in HSV format.
- Return type:
numpy.ndarray
- cv3.color_spaces.rgb2hsv(img)[source]
Convert image from RGB to HSV color space.
- Parameters:
img (numpy.ndarray) – Input image in RGB format.
- Returns:
Image in HSV format.
- Return type:
numpy.ndarray
- cv3.color_spaces.hsv2bgr(img)[source]
Convert image from HSV to BGR color space.
- Parameters:
img (numpy.ndarray) – Input image in HSV format.
- Returns:
Image in BGR format.
- Return type:
numpy.ndarray
- cv3.color_spaces.hsv2rgb(img)[source]
Convert image from HSV to RGB color space.
- Parameters:
img (numpy.ndarray) – Input image in HSV format.
- Returns:
Image in RGB format.
- Return type:
numpy.ndarray
- cv3.color_spaces.rgba(img)
Alias for
rgba2bgra().
- cv3.color_spaces.bgra(img)
Alias for
bgra2rgba().
|
Convert image between different color spaces. |
|
Alias for |
|
Convert image from RGB to BGR color space. |
|
Convert image from BGR to RGB color space. |
|
Convert image from RGBA to BGRA color space. |
|
Convert image from BGRA to RGBA color space. |
|
Convert image from RGB to grayscale. |
|
Convert image from BGR to grayscale. |
|
Convert grayscale image to RGB. |
|
Convert grayscale image to BGR. |
|
Convert grayscale image to RGBA. |
|
Convert grayscale image to BGRA. |
|
Convert image from BGR to HSV color space. |
|
Convert image from RGB to HSV color space. |
|
Convert image from HSV to BGR color space. |
|
Convert image from HSV to RGB color space. |
|
Alias for |
|
Alias for |
|
Alias for |
|
Alias for |