dtao / nearest-color

Find the nearest color
danieltao.com/nearest-color
MIT License
342 stars 31 forks source link

Feature Ideas #11

Open jlarmstrongiv opened 5 years ago

jlarmstrongiv commented 5 years ago

Features

Perceptual Distance

I like this library a lot! However, by using the pure and numerical RGB approach, this library does not calculate the closest color according to human perception.

It would be great to support a custom distance algorithm, such as one from DeltaE.

.nearestColors() // returns array

Also, if this library is used to present colors to the user, it may be beneficial to present say, the top five closest colors. Or, perhaps re-order the entire color array according to closest distance.

Custom color dictionaries

I am working with color dictionaries (aka Pantone) that define multiple properties of colors. For instance, it uses array of colors that look like:

// CMYK
    {
      "name": "3514 UP",
      "model": "CMYK",
      "color": [
        0,
        0.20000000298023224,
        1,
        0
      ],
      "type": "normal"
    },
// RGB
        {
          "name": "3514 UP",
          "model": "RGB",
          "color": [
            0.9529411792755127,
            0.7019608020782471,
            0.23137255012989044
          ],
          "type": "normal"
        },

There are many types of color formats as well. Chroma.js supports many of these color formats.

It would be great to support passing in a colors array of objects, and specifying the key where the color could be found.

Implementation Intricacies

The trouble is that different distance calculators require different color modes. For example, the current distance calculator in this library uses hex codes. The DeltaE distance calculator uses Lab colors.

I think the user should be responsive for providing the right format for the right distance calculator. That way, the user could cache the results of color converting RGB => Hex or RGB => Lab (etc).

Using color dictionaries would allow users to save the pre-computed results of those color conversions within the colors array itself. For instance, when nearestColor() is called multiple times, it knows the key/path of the pre-computed color and saves time. Thus, the user (not this library) will choose its preferred way of converting colors and caching them.

These ideas may necessitate a V2 of the nearest-color package. However, it will add beneficial features. What do you think? If nearest-color isn’t the right package for these features, please let me know, and I’ll create a different package.

remjx commented 4 years ago

hi @jlarmstrongiv, have you found a different solution that incorporates these features? Or still just ideas at this point?

jlarmstrongiv commented 4 years ago

Happy Easter 🐣@markjackson02 Unfortunately, I haven’t found any alternative solutions. Just ideas at this point. Personally, I’m building on a little color web app and haven’t worked on that feature yet

heyaco commented 4 years ago

@jlarmstrongiv did you get to implementing these ideas yet? I know it's only been a few months but I like your ideas and would like to apply them :)

jlarmstrongiv commented 4 years ago

Hi @starkana While I created an mvp for the color app, I ran out of time to include this feature. I would love to work on the project more, but I am in need of finding a job. After that, there’s a good chance it’ll be my weekend project :)

t0mpr1c3 commented 1 year ago

https://zschuessler.github.io/DeltaE/learn/

t0mpr1c3 commented 1 year ago

https://en.wikipedia.org/wiki/CIELAB_color_space