halostatue / color

Color tools for Ruby.
Other
133 stars 41 forks source link

Updates Color::RGB.closest_match to use the newer CIEDE2000 algorithm. #16

Closed ehlertij closed 2 years ago

ehlertij commented 9 years ago

This implements the newer CIEDE2000 color difference algorithm for use with Color::RGB.closest_match. The Wikipedia article on Color Difference outlines the benefits of this algorithm over the older CIE94 version. The main benefit is that it compensates for some inconsistencies in the blue region.

To implement this I used the implementation steps from this research document, and I matched all the lines back to the numbers outlined in the document. This should, hopefully, make it a little easier to follow.

I do not claim to be an expert on color theory, but I'm fairly confident that I implemented this algorithm correctly. I've done a lot of manual testing as well as automated testing, and so far it is surpasses or is comparable to the CIE94 version in all respects.

Again, the main benefit of this the blue region. Color set that I found particularly bad with the CIE94 version is very dark blues that appear black, but were mapping to a Midnight Blue color instead. This version of the algorithm fixes the problem. Here's an example:

This color (#29212C): screen shot 2015-01-20 at 4 40 53 pm

When given these two colors to find as its closest match: Black (#000000): screen shot 2015-01-20 at 4 41 12 pm

MidnightBlue (#191970): screen shot 2015-01-20 at 4 41 46 pm

With the CIE94 algorithm it matches to MidnightBlue. With the CIEDE2000 algorithm it matches to Black instead (which is visually correct).

I also had to update the test that was matching Firebrick to Crimson when given the choice between Crimson and DarkRed. The CIEDE2000 algorithm matches it to DarkRed instead of Crimson, which, in my opinion at least, is a very slightly closer visual match.

Firebrick: screen shot 2015-01-20 at 4 46 39 pm

DarkRed: screen shot 2015-01-20 at 4 46 46 pm

Crimson: screen shot 2015-01-20 at 4 46 54 pm

halostatue commented 9 years ago

Looks good.

coveralls commented 9 years ago

Coverage Status

Coverage decreased (-3.42%) when pulling 739df5b425b5e5e5c3968f36cf964fdc40ea108f on ehlertij:ciede2000-color-diff into 4e24c50261a8a73673ae12ce0955ecd4732702e6 on halostatue:master.

halostatue commented 9 years ago

I need to look at the current status of the Color project before I merge this, but I expect to merge this soon.

daveheitzman commented 9 years ago

Having written an implementation of this myself, I was curious if the new one tests out okay. It does! It passed the tests I had written for my own.

I have unmerged changes, largely dealing with putting Lab into its own class and contrast routines . LMK if interested in a merge request for those.

halostatue commented 9 years ago

@daveheitzman, I am definitely interested in getting this sorted out and don’t see the time to do so in the near future. There’s several PRs that are implementing similar things that I haven’t had time to examine.

halostatue commented 9 years ago

Sorry, I realized I didn’t answer your question (@daveheitzman): yes, I want that PR, but it may take a bit of time to get it reviewed by me. You’re a collaborator, so if you want to look at merging this in with an eye toward this work and other work you’ve got for open PRs becoming Color 2.0, that would be best IMO.

ehlertij commented 9 years ago

Thanks much @halostatue and @daveheitzman!

coveralls commented 8 years ago

Coverage Status

Coverage decreased (-3.6%) to 93.339% when pulling be035199474f7908c99b5bcc9bed356fa408c3b4 on ehlertij:ciede2000-color-diff into 4e24c50261a8a73673ae12ce0955ecd4732702e6 on halostatue:master.