DEV Community

Samandar Ravshanov
Samandar Ravshanov

Posted on

2 2

📦 CIEDE2000 color difference algorithm

from functorflow import ff

# ------ Returns the closest color ---------

color = { 'R': 255, 'G': 1, 'B': 30 }

#  red, green, blue

palette = [ {'R': 255, 'G': 0, 'B': 0 },
            {'R': 0, 'G': 255, 'B': 0 },
            {'R': 0, 'G': 0, 'B': 255} ]

print(ff('color-diff').closest(color, palette))
# {R: 255, G: 0, B: 0 }, red



# ------ Return the most different color -----------

color = { 'R': 255, 'G': 255, 'B': 255 };
# black, white
palette = [ {'R': 0, 'G': 0, 'B': 0 }, {'R': 255, 'G': 255, 'B': 255 } ];

print(ff('color-diff').furthest(color, palette)) 
# {'R': 0, 'G': 0, 'B': 0 }, black
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay