Image Segmentation · Cornea

What is LAB Color Segmentation?

LAB color segmentation solves the problem of selecting pixels with bounds that better reflect perceived lightness and color differences. Learn the CIELAB conversion, opponent channels, threshold geometry, and how to use it in the Telekinesis Agentic OS.

Imagine inspecting painted panels whose acceptable colors were specified by how different they should look to a human observer. Raw RGB distance is a poor match for that requirement: the same numeric step can look large in one region of the RGB cube and small in another. LAB was designed to make color differences more perceptually meaningful.

1. What is LAB Color Segmentation?

LAB color segmentation is a deterministic algorithm that converts pixels into CIE lightness and opponent-color coordinates, then labels pixels inside chosen bounds. It solves color-selection tasks where separating lightness from chromatic color—and reasoning about visually similar colors—is more useful than thresholding raw camera channels.

The three coordinates are L∗L^* for lightness, a∗a^* for the green–red opponent direction, and b∗b^* for the blue–yellow opponent direction. Telekinesis exposes the practical eight-bit LAB representation, whose channel values are supplied as integers from 0 to 255.

1.1 The Complete LAB Segmentation Path

RGB → perceptual coordinates → mask

RGB imageCamera color pixels
LAB boundsAccepted lightness and opponent colors
Linearize + XYZUndo display encoding and reference a white point
CIELAB conversionCompute L*, a*, and b* coordinates
Range comparisonTest all three LAB channels
Binary label map0 background, 1 selected color

LAB makes numerical color differences more perceptually meaningful, but it does not make camera color invariant to illumination or white balance.

LAB segmentation converts camera RGB values through a reference color space and thresholds lightness plus two opponent-color coordinates. Adapted as an explanatory diagram fromCIE 1976 L*a*b* colour space.

LAB segmentation also begins with the RGB values stored by the camera, but it converts them into coordinates designed to separate lightness from opponent color directions. This is useful when the task is closer to “find colors similar to this reference” than “keep pixels with a high red channel.”

The conversion has several steps because encoded RGB is tied to a display-oriented color space. The values are first linearized, then converted through the device-independent CIE XYZ representation. A reference white establishes what counts as neutral illumination, and a nonlinear mapping finally produces L∗L^*, a∗a^*, and b∗b^*.

Once each pixel has those three coordinates, segmentation is simple again. The algorithm checks whether lightness lies inside its allowed range and whether both opponent-color values lie inside theirs. Pixels passing all three tests become foreground.

The complex part is therefore the coordinate conversion, not the final threshold. That conversion makes color differences more meaningful, but its result still depends on the assumed RGB encoding, white point, and camera processing. The interactive view introduces the LAB axes before the mathematics below.

Interactive color coordinates

Describe the same pixel in four color spaces

#3b82f6
selected pixel
after brightness
RGBencoded channel intensities
HSVhue · saturation · value
LABlightness · green/red · blue/yellow
YCrCbluma · red difference · blue difference
Increase and decrease brightness. RGB channels and lightness move strongly, while hue or chroma may remain more stable—but no transform makes color independent of real illumination.

1.2 Lightness and Opponent Colors

L∗L^* runs from black toward diffuse white. The a∗a^* axis moves from greenish values toward reddish values, while b∗b^* moves from bluish toward yellowish values. This separates “how light is it?” from two chromatic directions.

For normalized tristimulus ratios x=X/Xnx=X/X_n, y=Y/Yny=Y/Y_n, and z=Z/Znz=Z/Z_n, CIELAB is defined using a piecewise function ff:

L∗=116f(y)−16,a∗=500[f(x)−f(y)],b∗=200[f(y)−f(z)].L^*=116f(y)-16,\qquad a^*=500[f(x)-f(y)],\qquad b^*=200[f(y)-f(z)].

Here, X,Y,ZX,Y,Z are the pixel’s CIE tristimulus values; Xn,Yn,ZnX_n,Y_n,Z_n describe the reference white; and ff is the standard cube-root/linear transition used by CIELAB. The white point matters because LAB describes color relative to an assumed reference illumination.

1.3 Why Perceptual Uniformity Helps

CIELAB was designed so equal coordinate changes correspond roughly—not perfectly—to equal perceived changes. A familiar color-distance measure is

ΔEab=(ΔL∗)2+(Δa∗)2+(Δb∗)2.\Delta E_{ab}=\sqrt{(\Delta L^*)^2+(\Delta a^*)^2+(\Delta b^*)^2}.

ΔL∗\Delta L^*, Δa∗\Delta a^*, and Δb∗\Delta b^* are the coordinate differences between two colors; ΔEab\Delta E_{ab} is their Euclidean distance in LAB space. More modern ΔE\Delta E formulas improve perceptual agreement, but this equation captures the motivation.

The Telekinesis Skill uses channel bounds rather than a spherical ΔE\Delta E radius. Geometrically, it selects a rectangular box in LAB space. That is still often easier to tune by eye than an RGB box because lightness can be widened independently of the opponent-color axes.

1.4 The Range Test and Its Trade-off

Let the converted pixel be q=(L,A,B)\mathbf q=(L,A,B) in the implementation’s eight-bit representation. It becomes foreground if

lL≤L≤uL,lA≤A≤uA,lB≤B≤uB.l_L\le L\le u_L,\qquad l_A\le A\le u_A,\qquad l_B\le B\le u_B.

The ll and uu symbols are lower and upper bounds for each stored LAB channel. Widening only the lightness interval tolerates shadows without admitting unrelated hues as readily as widening all three RGB channels. Widening AA or BB accepts more chromatic variation.

LAB is not magic illumination invariance. A different lamp changes the light reaching the camera; automatic white balance changes RGB before conversion; glossy reflections mix illuminant and surface color. The conversion reorganizes color information but cannot recover a material’s true reflectance from one uncalibrated image.

1.5 Why LAB Thresholding Is Not a Trained Model

LAB conversion follows a colorimetric standard and thresholding follows a fixed comparison rule. There are no learned weights, training examples, or loss function. Bounds can be selected from sampled colors or optimized on labeled masks, but that validation process does not train a neural network.

When evaluating, do not report only average IoU. Paint inspection may care much more about false acceptance of a wrong color than about missing a few boundary pixels. Choose metrics that match the decision the robot will make.

1.6 When LAB Is the Right Coordinate System

LAB is valuable when the accepted range is naturally described as a lightness tolerance plus chromatic tolerances, or when engineering specifications already use CIELAB and ΔE\Delta E. HSV is often easier for a simple “find all blue objects” rule. RGB can be simpler and faster when the imaging setup is locked.

All three remain pixel classifiers. They cannot distinguish two objects with the same color, understand a part name, or infer which colored region is graspable. Pair color segmentation with component filtering and geometry—or move to a learned model when identity rather than color carries the answer.

1.7 LAB Bounds and Color-Distance Rules Are Different

An axis-aligned LAB range and a ΔE\Delta E tolerance do not select the same shape. Bounds create a rectangular box: a pixel can independently use the full allowed deviation on LL, aa, and bb. A simple ΔEab\Delta E_{ab} threshold creates a sphere around a reference color.

The box is convenient when tolerances differ by coordinate. You might allow wide lightness variation from shadows but only small chromatic variation. A distance rule is convenient when the specification says every direction of color change should count similarly. Understanding that geometry prevents an engineer from interpreting channel bounds as if they were a formal ΔE\Delta E paint tolerance.

1.8 Stored Eight-Bit LAB Is Not the Textbook Scale

Textbooks commonly show L∗L^* from 0 to 100 and signed a∗a^* and b∗b^* values around zero. Image libraries often store LAB in unsigned eight-bit channels so it fits the same memory layout as an RGB image. Lightness is scaled, while the two opponent channels are shifted into a non-negative range.

That is why Telekinesis bounds use values from 0 to 255. Do not paste a signed laboratory a∗a^* tolerance directly into an eight-bit API. First establish the conversion and encoding used by the image pipeline, then sample the deployed image values.

1.9 White Balance and the Reference White

CIELAB is defined relative to a reference white, and the RGB-to-LAB pipeline carries assumptions about primaries, transfer functions, and white point. Meanwhile, a camera may already have applied automatic white balance. Two cameras looking at the same panel can therefore produce different stored LAB coordinates.

For repeatable inspection, lock camera processing, keep illumination stable, and calibrate bounds separately when sensors or optics change. If the application claims traceable color measurement rather than practical image segmentation, use a calibrated color-measurement workflow; a convenient camera conversion is not automatically a colorimeter.

1.10 Build a Mask Evaluation Around the Decision

For object isolation, pixel IoU and boundary error may be suitable. For paint acceptance, measure false acceptance and false rejection at the part level. For robot picking, measure centroid and pose error after connected-component filtering. The best color space is the one that makes the final operational decision stable—not necessarily the one with the prettiest example mask.

Always include distractors close to the acceptance boundary. A test set containing only vivid target colors and neutral backgrounds cannot reveal whether LAB is providing useful separation.

2. How to Use LAB Segmentation in the Telekinesis Agentic OS

Telekinesis provides LAB thresholding as the Cornea Skill segment_image_using_lab. The code loads a painting scene and returns a SegmentationImage with labels 0 and 1.

from telekinesis import cornea, datatypes

image = datatypes.Image.from_url(
    url="https://assets.telekinesis.ai/examples/v1/images/car_painting.jpg"
)

mask = cornea.segment_image_using_lab(
    image=image,
    lower_bound=(120, 50, 50),
    upper_bound=(180, 255, 255),
)

print(mask.shape, mask.label_codes, mask.number_of_labels)

Binary mask produced by LAB color thresholding

The selected region lies inside the supplied LAB box. Validate the same bounds under every allowed camera and lighting condition.

Try it out

Build with LAB segmentation in Cornea

See the complete Skill signature, LAB channel bounds, output schema, and current examples.

Open LAB segmentation docs

Runnable example

Run the LAB segmentation example

Open the exact Python script used to threshold an image in LAB space with Cornea.

View Python example

3. Benchmarking

LAB thresholding has no learned checkpoint to benchmark. Compare RGB, HSV, and LAB on the same labeled deployment images. Report pixel precision, recall, IoU, color false-accept rate, component stability, and latency; stratify results by illumination, exposure, surface gloss, and camera.

4. Where to Go Next?

5. References