Skip to content

labEdgeDensity

labEdgeDensity(pixels, width): number

Defined in: packages/math-color/src/models/lab-edge-density.ts:25

Computes the mean gradient magnitude of the OKLab L channel across all interior pixels.

Uses a central-difference approximation (one-step horizontal and vertical):

dx = L[x+1, y] − L[x−1, y]
dy = L[x, y+1] − L[x, y−1]
magnitude = √(dx² + dy²)

Border pixels are excluded (no padding or clamping applied). At a typical 80 × 80 downscale this covers ~6 241 interior pixels — negligible cost.

For OKLab, range is [0, ~1.41]. Typical values: featureless sky ≈ 0.005, calm landscape ≈ 0.02–0.04, busy scene ≥ 0.06. For CIE L_a_b*, range is [0, ~2.55]. Typical values: featureless sky ≈ 0.01, calm landscape ≈ 0.04–0.08, busy scene ≥ 0.12.

readonly LabCoords[]

Flat row-major pixel array

number

Width of the source image in pixels

number

Mean gradient magnitude.