Color Space Conversion
Convert color space of image
Libraries:
Computer Vision Toolbox /
Conversions
Description
The Color Space Conversion block converts color information between color spaces. Use the Conversion parameter to specify the color spaces you are converting between.
Examples
Convert Image Color Space from RGB to YCbCr
Convert an image color space from RGB to YCbCr.
Ports
Input
Port_1 — Input image
array
Input image, specified as an M-by-N-by-C array, where C is the number of color channels in the input image.
Data Types: single
| double
| uint8
R' — Red color component of image
matrix
Red color component of image, specified as an M-by-N matrix.
Note
Inputs to the R', G', and B' ports must have the same dimensions and data type as one another.
Dependencies
To enable this port, set the Image signal parameter to
Separate color signals
and set the
Conversion parameter to one of these options:
R'G'B' to Y'CbCr
R'G'B' to intensity
R'G'B' to HSV
sR'G'B' to XYZ
sR'G'B' to L*a*b*
Data Types: single
| double
| uint8
G' — Green color component of image
matrix
Green color component of image, specified as an M-by-N matrix.
Note
Inputs to the R', G', and B' ports must have the same dimensions and data type as one another.
Dependencies
To enable this port, set the Image signal parameter to
Separate color signals
and set the
Conversion parameter to one of these options:
R'G'B' to Y'CbCr
R'G'B' to intensity
R'G'B' to HSV
sR'G'B' to XYZ
sR'G'B' to L*a*b*
Data Types: single
| double
| uint8
B' — Blue color component of image
matrix
Blue color component of image, specified as an M-by-N matrix.
Note
Inputs to the R', G', and B' ports must have the same dimensions and data type as one another.
Dependencies
To enable this port, set the Image signal parameter to
Separate color signals
and set the
Conversion parameter to one of these options:
R'G'B' to Y'CbCr
R'G'B' to intensity
R'G'B' to HSV
sR'G'B' to XYZ
sR'G'B' to L*a*b*
Data Types: single
| double
| uint8
Y' — Luma component of image
matrix
Luma component of image, specified as an M-by-N matrix.
Dependencies
To enable this port, set the Image signal parameter to
Separate color signals
and set the
Conversion parameter to Y'CbCr to
R'G'B'
.
Data Types: single
| double
| uint8
Cb — Blue-difference chroma component of image
matrix
Blue-difference chroma component of image, specified as an M-by-D matrix, where D is half the width of the image.
Dependencies
To enable this port, set the Image signal parameter to
Separate color signals
and set the
Conversion parameter to Y'CbCr to
R'G'B'
.
Data Types: single
| double
| uint8
Cr — Red-difference chroma component of image
matrix
Red-difference chroma component of image, specified as an M-by-D matrix, where D is half the width of the image.
Dependencies
To enable this port, set the Image signal parameter to
Separate color signals
and set the
Conversion parameter to Y'CbCr to
R'G'B'
.
Data Types: single
| double
| uint8
H — Hue component of image
matrix
Hue component of image, specified as an M-by-N matrix.
Note
Inputs to the H, S, and V ports must have the same dimensions and data type as one another.
Dependencies
To enable this port, set the Image signal parameter to
Separate color signals
and set the
Conversion parameter to HSV to
R'G'B'
.
Data Types: single
| double
S — Saturation component of image
matrix
Saturation component of image, specified as an M-by-N matrix.
Note
Inputs to the H, S, and V ports must have the same dimensions and data type as one another.
Dependencies
To enable this port, set the Image signal parameter to
Separate color signals
and set the
Conversion parameter to HSV to
R'G'B'
.
Data Types: single
| double
V — Brightness component of image
matrix
Brightness component of image, specified as an M-by-N matrix.
Note
Inputs to the H, S, and V ports must have the same dimensions and data type as one another.
Dependencies
To enable this port, set the Image signal parameter to
Separate color signals
and set the
Conversion parameter to HSV to
R'G'B'
.
Data Types: single
| double
X — X component of image
matrix
X component of image, specified as an M-by-N matrix.
Note
Inputs to the X, Y, and Z ports must have the same dimensions and data type as one another.
Dependencies
To enable this port, set the Image signal parameter to
Separate color signals
and set the
Conversion parameter to XYZ to
sR'G'B'
.
Data Types: single
| double
Y — Y component of image
matrix
Y component of image, specified as an M-by-N matrix.
Note
Inputs to the X, Y, and Z ports must have the same dimensions and data type as one another.
Dependencies
To enable this port, set the Image signal parameter to
Separate color signals
and set the
Conversion parameter to XYZ to
sR'G'B'
.
Data Types: single
| double
Z — Z component of image
matrix
Z component of image, specified as an M-by-N matrix.
Note
Inputs to the X, Y, and Z ports must have the same dimensions and data type as one another.
Dependencies
To enable this port, set the Image signal parameter to
Separate color signals
and set the
Conversion parameter to XYZ to
sR'G'B'
.
Data Types: single
| double
L* — Lightness component of image
matrix
Lightness component of image, specified as an M-by-N matrix.
Note
Inputs to the L*, a*, and b* ports must have the same dimensions and data type as one another.
Dependencies
To enable this port, set the Image signal parameter to
Separate color signals
and set the
Conversion parameter to L*a*b* to
sR'G'B'
.
Data Types: single
| double
a* — Red-green component of image
M-by-N matrix
Red-green component of image, specified as an M-by-N matrix.
Note
Inputs to the L*, a*, and b* ports must have the same dimensions and data type as one another.
Dependencies
To enable this port, set the Image signal parameter to
Separate color signals
and set the
Conversion parameter to L*a*b* to
sR'G'B'
.
Data Types: single
| double
b* — Yellow-blue component of image
M-by-N matrix
Yellow-blue component of image, specified as an M-by-N matrix.
Note
Inputs to the L*, a*, and b* ports must have the same dimensions and data type as one another.
Dependencies
To enable this port, set the Image signal parameter to
Separate color signals
and set the
Conversion parameter to L*a*b* to
sR'G'B'
.
Data Types: single
| double
Output
Port_1 — Output image
array
Output image, returned as an M-by-N-by-P array, where P is the number of color channels in the output image. For Y'CbCr output, the value range for the Y component differs from those of the Cb and Cr components.
If the input is
uint8
, then Y'CbCr isuint8
.Y'
is in the range[16, 235]
, andCb
andCr
are in the range[16, 240]
.If the input is
double
, thenY'CbCr
isdouble
.Y'
is in the range[16/255, 235/255]
, andCb
andCr
are in the range[16/255, 240/255]
.
Data Types: single
| double
| int8
| uint8
R' — Red color component of image
matrix
Red color component of image, returned as an M-by-N matrix.
Dependencies
To enable this port, set the Image signal parameter to
Separate color signals
and set the
Conversion parameter to one of these options:
Y'CbCr to R'G'B'
HSV to R'G'B'
XYZ to sR'G'B'
L*a*b* to sR'G'B'
.
Data Types: single
| double
| int8
| uint8
G' — Green color component of image
matrix
Green color component of image, returned as an M-by-N matrix.
Dependencies
To enable this port, set the Image signal parameter to
Separate color signals
and set the
Conversion parameter to one of these options:
Y'CbCr to R'G'B'
HSV to R'G'B'
XYZ to sR'G'B'
L*a*b* to sR'G'B'
Data Types: single
| double
| int8
| uint8
B' — Blue color component of image
matrix
Blue color component of image, returned as an M-by-N matrix.
Dependencies
To enable this port, set the Image signal parameter to
Separate color signals
and set the
Conversion parameter to one of these options:
Y'CbCr to R'G'B'
HSV to R'G'B'
XYZ to sR'G'B'
L*a*b* to sR'G'B'
.
Data Types: single
| double
| int8
| uint8
Y' — Luma component of image
matrix
Luma component of image, returned as an M-by-N matrix.
Dependencies
To enable this port, set the Image signal parameter to
Separate color signals
and set the
Conversion parameter to R'G'B' to
Y'CbCr
.
Data Types: single
| double
| int8
| uint8
Cb — Blue-difference chroma component of image
matrix
Blue-difference chroma component of image, returned as an M-by-N matrix.
Dependencies
To enable this port, set the Image signal parameter to
Separate color signals
and set the
Conversion parameter to R'G'B' to
Y'CbCr
.
Data Types: single
| double
| int8
| uint8
Cr — Red-difference chroma component of image
matrix
Red-difference chroma component of image, returned as an M-by-N matrix.
Dependencies
To enable this port, set the Image signal parameter to
Separate color signals
and set the
Conversion parameter to R'G'B' to
Y'CbCr
.
Data Types: single
| double
| int8
| uint8
I' — Intensity image
matrix
Intensity image, returned as an M-by-N matrix.
Dependencies
To enable this port, set the Image signal parameter to
Separate color signals
and set the
Conversion parameter to R'G'B' to
intensity
.
Data Types: single
| double
| int8
| uint8
H — Hue component of image
matrix
Hue component of image, returned as an M-by-N matrix.
Dependencies
To enable this port, set the Image signal parameter to
Separate color signals
and set the
Conversion parameter to R'G'B' to
HSV
.
Data Types: single
| double
S — Saturation component of image
matrix
Saturation component of image, returned as an M-by-N matrix.
Dependencies
To enable this port, set the Image signal parameter to
Separate color signals
and set the
Conversion parameter to R'G'B' to
HSV
.
Data Types: single
| double
V — Brightness component of image
matrix
Brightness component of image, returned as an M-by-N matrix.
Dependencies
To enable this port, set the Image signal parameter to
Separate color signals
and set the
Conversion parameter to R'G'B' to
HSV
.
Data Types: single
| double
X — X component of image
matrix
X component of image, returned as an M-by-N matrix.
Dependencies
To enable this port, set the Image signal parameter to
Separate color signals
and set the
Conversion parameter to sR'G'B' to
XYZ
.
Data Types: single
| double
Y — Y component of image
matrix
Y component of image, returned as an M-by-N matrix.
Dependencies
To enable this port, set the Image signal parameter to
Separate color signals
and set the
Conversion parameter to sR'G'B' to
XYZ
.
Data Types: single
| double
Z — Z component of image
matrix
Z component of image, returned as an M-by-N matrix.
Dependencies
To enable this port, set the Image signal parameter to
Separate color signals
and set the
Conversion parameter to sR'G'B' to
XYZ
.
Data Types: single
| double
L* — Lightness component of image
matrix
Lightness component of image, returned as an M-by-N matrix.
Dependencies
To enable this port, set the Image signal parameter to
Separate color signals
and set the
Conversion parameter to sR'G'B' to
L*a*b*
.
Data Types: single
| double
a* — Red-green component of image
matrix
Red-green component of image, returned as an M-by-N matrix.
Dependencies
To enable this port, set the Image signal parameter to
Separate color signals
and set the
Conversion parameter to sR'G'B' to
L*a*b*
.
Data Types: single
| double
b* — Yellow-blue component of image
matrix
Yellow-blue component of image, returned as an M-by-N matrix.
Dependencies
To enable this port, set the Image signal parameter to
Separate color signals
and set the
Conversion parameter to sR'G'B' to
L*a*b*
.
Data Types: single
| double
Parameters
Conversion — Color space conversion
R'G'B' to Y'CbCr
(default) | Y'CbCr to R'G'B'
| R'G'B' to intensity
| ...
Specify which color space to convert the image from and to using these options:
R'G'B' to Y'CbCr
Y'CbCr to R'G'B'
R'G'B' to intensity
B'G'R' to intensity
B'G'R' to R'G'B'
R'G'B' to B'G'R'
R'G'B' to HSV
HSV to R'G'B'
sR'G'B' to XYZ
XYZ to sR'G'B'
sR'G'B' to L*a*b*
L*a*b* to sR'G'B'
Note
The prime notation indicates that the signal is gamma corrected.
Use conversion specified by — Color conversion standard
Rec. 601 (SDTV)
(default) | Rec. 709 (HDTV)
Specify the color conversion standard for converting the image between the R'G'B'
and Y'CbCr color spaces as either Rec. 601 (SDTV)
or
Rec. 709 (HDTV)
.
Dependencies
To enable this parameter, set the Conversion parameter to
R'G'B' to Y'CbCr
or Y'CbCr to
R'G'B'
.
Scanning standard — Scanning standard
1125/60/2:1
(default) | 1250/50/2:1
Specify the scanning standard for converting the image between the R'G'B' and Y'CbCr
color spaces as either 1125/60/2:1
or
1250/50/2:1
.
Dependencies
To enable this parameter, set the Conversion parameter to
R'G'B' to Y'CbCr
or Y'CbCr to
R'G'B'
and set the Use conversion specified by
parameter to Rec. 709 (HDTV)
.
White point — White point
D50
(default) | D55
| D65
Specify the reference white point for converting the image between the sR'G'B' and
L*a*b* color spaces as D50
, D55
,
or D65
.
Dependencies
To enable this parameter, set the Conversion parameter to
sR'G'B' to L*a*b*
or L*a*b* to
sR'G'B'
.
Image signal — Image signal input
One multidimensional signal
(default) | Separate color signals
Specify whether to combine the color channels of the image into one signal or input and output them individually.
One multidimensional signal
— The block accepts all color channels of the input image as a multidimensional array to a single input port, and outputs the converted image as a single matrix or array from a single output port.Separate color signals
— The block accepts each color channel of the input image to a separate input port, and outputs each color channel of the converted image from a separate output port.
Block Characteristics
Data Types |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
Algorithms
Conversion Between R'G'B' and Y'CbCr Color Spaces
These equations define R'G'B' to Y'CbCr conversion and Y'CbCr to R'G'B' conversion, respectively:
The values in matrices A
and B
are based on your
choices for the Use conversion specified by and Scanning
standard parameters.
Matrix | Use conversion specified by = Rec. 601 (SDTV) | Use conversion specified by = Rec. 709 (HDTV) | |
---|---|---|---|
Scanning standard = 1125/60/2:1 | Scanning standard = 1250/50/2:1 | ||
A | |||
B |
Conversion from R'G'B' to Intensity
This equation defines conversion from the R'G'B' color space to an intensity image:
Conversion from B'G'R' to Intensity
This equation defines conversion from the B'G'R' color space to an intensity image:
Conversion Between R'G'B' and HSV Color Spaces
In the equations defining the R'G'B' to HSV conversion, MAX and MIN are the highest and lowest component values, respectively, of a given R'G'B' triplet. H, S, and V vary from 0 to 1.
This equation defines the HSV to R'G'B' conversion, where M is the highest value among , and :
Conversion Between sR'G'B' and XYZ Color Spaces
The sR'G'B' to XYZ conversion is a two-step process. First, the block converts the gamma-corrected sR'G'B' values to linear sRGB values using these equations:
If , , and are each less than or equal to 0.03928, then:
Otherwise:
Then, the block converts the sRGB values to XYZ values using this equation:
The XYZ to sR'G'B' conversion is also a two-step process. First, the block converts the XYZ values to linear sRGB values using this equation:
Then the block applies gamma correction, using these equations, to obtain the sR'G'B' values:
If , and are each less than or equal to 0.00304, then:
Otherwise:
Note
Computer Vision Toolbox™ uses a D65 white point, which is specified in Recommendation ITU-R BT.709, for this conversion. In contrast, the Image Processing Toolbox™ conversion is based on ICC profiles, and it uses a D65 to D50 Bradford adaptation transformation to the D50 white point. If you are using these two products and comparing results, you must account for this difference.
Conversion Between sR'G'B' and L*a*b* Color Spaces
The Color Space Conversion block converts sR'G'B' values to L*a*b* values in two steps. First, it converts sR'G'B' to XYZ values using the equations described in Conversion Between sR'G'B' and XYZ Color Spaces. Then, it uses these equations to transform the XYZ values to L*a*b* values. Here, , , and are the tristimulus values of the reference white point you specify using the White point parameter:
If is greater than 0.008856, then:
Otherwise:
If t is greater than 0.008856, then:
Otherwise:
The block converts L*a*b* values to sR'G'B' values in two steps, as well. First, the block transforms the L*a*b* values to XYZ values using these equations:
If is greater than 0.008856, then:
where:
Otherwise:
Then it converts XYZ to sR'G'B' values using the equations described in Conversion Between sR'G'B' and XYZ Color Spaces.
References
[1] Poynton, Charles A. A Technical Introduction to Digital Video. New York: John Wiley & Sons, 1996.
[2] International Telecommunication Union (ITU). Studio Encoding Parameters of Digital Television for Standard 4:3 and Wide-Screen 16:9 Aspect Ratios. Recommendation ITU-R BT.601-5. Geneva, Switzerland: ITU, recommended October 1995; superseded January 2007.
[3] International Telecommunication Union (ITU). Parameter Values for the HDTV Standards for Production and International Programme Exchange. Recommendation ITU-R BT.709-5. Geneva, Switzerland: ITU, recommended April 2002; superseded June 2015.
[4] Stokes, Michael, Matthew Anderson, Srinivasan Chandrasekar, and Ricardo Motta. “A Standard Default Color Space for the Internet - sRGB. World Wide Web Consortium (W3C).” November 5, 1996. https://www.w3.org/Graphics/Color/sRGB.html
[5] Berns, Roy S., Fred W. Billmeyer, Max Saltzman, and Fred W. Billmeyer. Billmeyer and Saltzman’s Principles of Color Technology. 3rd ed. New York: Wiley, 2000.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.
Version History
Introduced before R2006a
See Also
Blocks
Functions
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)