How to compute Delta E CAM16 distance? #439
-
Hi everyone, I'm trying to compute distance between two colors in the CAM16 SCD space. Here is my code:
I got the following error: It is unclear to me if the formula to compute color distance changes or if it is always an Euclidean distance computed in different color space such as CAM16-UCS, CAM16-SCD, CAM16-LCD, ... I'm not even sure to perfectly understand what is exactly a color space. Thanks for your help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 52 replies
-
@tvaillantdeguelis You need to also register Also, there are many delta E methods, so you have to specify what you are using (in this case from coloraide import Color as Base
from coloraide.distance.delta_e_cam16 import DECAM16
from coloraide.spaces.cam16_ucs import CAM16UCS, CAM16SCD, CAM16LCD, CAM16JMh
class Color(Base): ...
Color.register([CAM16UCS(), CAM16SCD(), CAM16LCD(), DECAM16(), CAM16JMh()])
Color('#a7aaa0').delta_e('#e9daae', method='cam16', space='cam16-scd') You can see it working live here.
The CAM16 model came about to try and give better ∆E calculations. The best ∆E calculation in CIELab is ∆E2000 and it puts most of the complexity in the calculation to get pretty good ∆E values. It's a pretty ugly algorithm, but the results are pretty good. CAM16 puts most of the complexity in calculating the model which then makes the ∆E calculations more simple and closer to Euclidean distance. CAM16 also allows specifying exact lighting conditions allowing you to better simulate the viewing environment. UCS, SCD, and LCD were kind of designed to give more specific environments for testing distancing. Distancing is normally applied directly to CAM16, but usually in one of these specific forms of CAM16. Each one is supposedly better suited for specific distances, SCD being better for colors that are a shorter distance apart and LCD for colors at a greater, longer distance apart. Basically, the shape of the model distorted in these forms to give better calculations in these scenarios.
You and probably a lot of people 🙂. There's really a difference between model and space, and we usually just call everything a "space" to make things more accessible to the user. A model is like a way to represent colors. I can represent colors in the RGB model, meaning the color is transformed to some Red, Green, Blue values, but sRGB (standard RGB) is a specific RGB representation with an actual gamut (range of colors) and specific conditions. HSL is a model that transforms an RGB space to a cylindrical form, but traditionally, it is still the sRGB space's gamut underneath, but it doesn't have to be. CAM16 doesn't really have a specific gamut, it is more a way of taking colors and arranging them so they are more perceptually uniform, it's more of a model. A lot of these perceptual color spaces came about specifically to calculate better color distances amount other things. Ideally to get closer to Euclidean distance. |
Beta Was this translation helpful? Give feedback.
@tvaillantdeguelis You need to also register
CAM16JMh
as that is the model we got through to get to CAM16 UCS, SCD, and LCD. This map shows what spaces everything passes through to get to what: https://facelessuser.github.io/coloraide/colors/#color-space-map. Granted, I do see the Delta E docs do not specifically mentionCAM16JMh
which is a mistake on my part. I'll have to correct that.Also, there are many delta E methods, so you have to specify what you are using (in this case
method='cam16'
) or it assumes ∆E76 IIRC, which uses CIELab. It probably wouldn't hurt if I showed that part in the example as well and not just the registering of the plugins.