Menu

Client-Side CIEDE2000 Color Quantization: Matching RGB Images & Pixel Art to 447 DMC Embroidery Threads in JavaScript
📰

Client-Side CIEDE2000 Color Quantization: Matching RGB Images & Pixel Art to 447 DMC Embroidery Threads in JavaScript

DEV Community: fastapi·teasoup90·about 8 hours ago
#GI2RE7Yf
#devtofastapi#devto#dev#pixel#photographs
Long article (276 words) — no AI summary yet.
Reading 0:00
15s threshold

Converting arbitrary RGB pixel art or photographs into stitchable embroidery charts is much harder than nearest-neighbor RGB matching. Standard Euclidean distance in sRGB space over-weights luminance errors and produces muddy skin tones or shifted blues when restricted to a fixed 447-color palette like DMC stranded cotton.

To get perceptually accurate thread matches entirely in the browser, you need a three-stage color pipeline:

1. Linearize sRGB and Convert to CIE L*a*b*

First, undo the gamma curve on each 8-bit channel before transforming through XYZ (D65 illuminant) into perceptual CIE L*a*b* :

const toLinear = ( c ) => { const s = c / 255 ; return s <= 0.04045 ? s / 12.92 : Math . pow ( ( s + 0.055 ) / 1.055 , 2.4 ) ; } ;

Enter fullscreen mode

Exit fullscreen mode

2. Score Against Precomputed DMC Lab Vectors Using CIEDE2000

Precomputing L*a*b* values for all 447 DMC thread codes at startup keeps per-pixel lookup fast.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.