rgb2lab
Convert RGB to CIE 1976 L*a*b*
Description
Examples
Convert RGB White to L*a*b*
Use rgb2lab
to convert the RGB white value to L*a*b.
rgb2lab([1 1 1])
ans = 1×3
100.0000 0 0.0000
Convert Color Value to L*a*b* Specifying Color Space
Convert an Adobe RGB (1998) color value to L*a*b* using the ColorSpace
parameter.
rgb2lab([.2 .3 .4],'ColorSpace','adobe-rgb-1998')
ans = 1×3
30.1783 -5.6902 -20.8223
Convert RGB color to L*a*b* Specifying Reference White
Use rgb2lab
to convert an RGB color to L*a*b using the D50 reference white.
rgb2lab([.2 .3 .4],'WhitePoint','d50')
ans = 1×3
31.3294 -4.0732 -18.1750
Convert RGB Image to L*a*b* and Display L* Component
Read RGB image into the workspace.
rgb = imread('peppers.png');
Convert the RGB image to the L*a*b* color space.
lab = rgb2lab(rgb);
Display the L* component of the L*a*b* image.
imshow(lab(:,:,1),[0 100])
Input Arguments
RGB
— RGB color values
numeric array
RGB color values to convert, specified as a numeric array in one of these formats.
c-by-3 colormap. Each row specifies one RGB color value.
m-by-n-by-3 image
m-by-n-by-3-by-p stack of images
Data Types: single
| double
| uint8
| uint16
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: lab = rgb2lab([0.25 0.40
0.10],WhitePoint="d50")
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: lab = rgb2lab([0.25 0.40 0.10],"WhitePoint","d50")
ColorSpace
— Color space of input RGB values
"srgb"
(default) | "adobe-rgb-1998"
| "prophoto-rgb"
| "linear-rgb"
Color space of the input RGB values, specified as
"srgb"
, "adobe-rgb-1998"
,
"prophoto-rgb"
, or
"linear-rgb"
. If you specify
"linear-rgb"
, then rgb2lab
assumes the input RGB values are linearized sRGB values.
Data Types: string
| char
WhitePoint
— Reference white point
"d65"
(default) | "a"
| "c"
| "e"
| "d50"
| "d55"
| "icc"
| 1-by-3 vector
Reference white point, specified as a 1-by-3 vector or one of the CIE standard illuminants listed in the table.
Value | White Point |
---|---|
"a" | CIE standard illuminant A, |
"c" | CIE standard illuminant C, [0.9807, 1.0000, 1.1822] . Simulates average or
north sky daylight with correlated color temperature of 6774 K. Deprecated by
CIE. |
"e" | Equal-energy radiator, [1.000, 1.000, 1.000] . Useful as a theoretical
reference. |
"d50" | CIE standard illuminant D50, [0.9642, 1.0000, 0.8251] .
Simulates warm daylight at sunrise or sunset with correlated color
temperature of 5003 K. Also known as horizon light. |
| CIE standard illuminant D55, |
"d65" | CIE standard illuminant D65, [0.9504, 1.0000, 1.0888] . Simulates noon
daylight with correlated color temperature of 6504 K. |
"icc" | Profile Connection Space (PCS) illuminant used in ICC profiles. Approximation of
[0.9642, 1.000, 0.8249] using fixed-point, signed, 32-bit
numbers with 16 fractional bits. Actual value: [31595,32768,
27030]/32768 . |
Data Types: single
| double
| string
| char
Output Arguments
lab
— Converted L*a*b* color values
numeric array
Converted L*a*b* color values, returned as a numeric array of the same
size as the input. The output type is double
unless the
input type is single
, in which case the output type is
also single
.
Attribute | Description |
---|---|
L* | Luminance or brightness of the image. Values are in the range [0, 100], where 0 specifies black and 100 specifies white. As L* increases, colors become brighter. |
a* | Amount of red or green tones in the image. A large positive a* value corresponds to red/magenta. A large negative a* value corresponds to green. Although there is no single range for a*, values commonly fall in the range [-100, 100] or [-128, 127). |
b* | Amount of yellow or blue tones in the image. A large positive b* value corresponds to yellow. A large negative b* value corresponds to blue. Although there is no single range for b*, values commonly fall in the range [-100, 100] or [-128, 127). |
Data Types: double
| single
Tips
If you specify the input RGB color space as
"linear-rgb"
, thenrgb2lab
assumes the input values are linearized sRGB values. If instead you want the input color space to be linearized Adobe RGB (1998), then you can use thelin2rgb
function.For example, to convert linearized Adobe RGB (1998) image
RGBlinadobe
to the CIE 1976 L*a*b* color space, perform the conversion in two steps:RGBadobe = lin2rgb(RGBlinadobe,"ColorSpace","adobe-rgb-1998"); LAB = rgb2lab(RGBadobe,"ColorSpace","adobe-rgb-1998");
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
rgb2lab
supports the generation of C code (requires MATLAB® Coder™). For more information, see Code Generation for Image Processing.When generating code, all character vector input arguments must be compile-time constants.
GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
Usage notes and limitations:
The
ColorSpace
name-value argument only supports the values"srgb"
,"adobe-rgb-1998"
, and"linear-rgb"
.When generating code, all character vector input arguments must be compile-time constants.
Thread-Based Environment
Run code in the background using MATLAB® backgroundPool
or accelerate code with Parallel Computing Toolbox™ ThreadPool
.
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
Version History
Introduced in R2014bR2022b: Support for ProPhoto (ROMM RGB) color space
rgb2lab
now supports the ProPhoto (ROMM RGB) color space,
which has a wider gamut than the sRGB and Adobe RGB 1998 color spaces. To use the
ProPhoto color space, specify the ColorSpace
name-value
argument as "prophoto-rgb"
.
R2022b: Support for thread-based environments
rgb2lab
now supports thread-based
environments.
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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)