rgb2lab — Convert RGB image, image-stack, or colormap values to CIE L*a*b*.
rgb2lab(RGB) converts RGB values to CIE L*a*b*. ColorSpace and WhitePoint name-value pairs select source primaries and reference white.
Syntax
LAB = rgb2lab(RGB, Name=Value)Inputs
RGB- Type
Any- Required
- Yes
- Description
- RGB image, image stack, or c-by-3 colormap values.
NameValue- Type
Any- Required
- Variadic
- Description
- ColorSpace or WhitePoint name-value options.
Returns
LAB- Type
NumericArray- Description
- CIE L*a*b* image or colormap converted from RGB input.
Errors
RunMat:rgb2lab:TooManyOutputs- When
- More than one output argument is requested.
- Message
rgb2lab: too many output arguments
RunMat:rgb2lab:TooManyInputs- When
- More than the two supported name-value pairs are supplied.
- Message
rgb2lab: too many input arguments
RunMat:rgb2lab:InvalidInput- When
- Input cannot be interpreted as an MxNx3 RGB image or Nx3 RGB colormap.
- Message
rgb2lab: invalid input
Classes and geometry
RGB accepts nonempty M-by-N-by-3 truecolor images, M-by-N-by-3-by-P stacks, and nonempty K-by-3 colormaps in single, double, uint8, or uint16. An image stack may have an empty trailing stack axis while M and N remain positive. Logical, complex, signed and wide unsigned integers, and other geometry reject.
uint8 and uint16 samples normalize by their full native range; floating samples clamp to [0,1]. Single input produces single Lab; double and integer input produce double. Shape is preserved, including stack axes.
Color controls
ColorSpace accepts case-insensitive srgb (default), adobe-rgb-1998, prophoto-rgb, or linear-rgb. WhitePoint accepts A, C, E, D50, D55, D65 (default), ICC, or a finite positive single/double 1-by-3 XYZ row. Up to two name-value pairs are accepted; repeated options use the last value.
Execution and compatibility
The channel-coupled host conversion is a fusion boundary. Parsed controls and admitted class, shape, and owner precede operand preparation. Resident output restores through the original owner when possible. Explicit gpuArray input requires the RunMat-only Rgb2labExplicitGpuExtension; automatic resident input may gather normally.
Examples
Convert RGB white to Lab
RGB = reshape([1 1 1],[1 1 3]); LAB = rgb2lab(RGB); size(LAB)Expected output:
ans = [1 1 3]Select a reference white
LAB = rgb2lab([1 0 0],'ColorSpace','srgb','WhitePoint','D50'); size(LAB)Expected output:
ans = [1 3]Using rgb2lab with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how rgb2lab changes the result.
Run a small rgb2lab example, explain the result, then change one input and compare the output.
Related Image functions
Source you can read
Every RunMat function's source is public. Read exactly how rgb2lab is executed, line by line, in Rust.
- View the source for rgb2lab in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.