Skip to content

Commit 01ae144

Browse files
committed
add ΔE_ITP color difference as differenceItp()
1 parent 53b4479 commit 01ae144

File tree

8 files changed

+36
-7
lines changed

8 files changed

+36
-7
lines changed

docs/api.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ codebase: 'https://github.com/evercoder/culori/blob/main'
2929
<li><a href='#differenceHueSaturation'>differenceHueSaturation</a></li>
3030
<li><a href='#differenceHyab'>differenceHyab</a></li>
3131
<li><a href='#differenceKotsarenkoRamos'>differenceKotsarenkoRamos</a></li>
32+
<li><a href='#differenceItp'>differenceItp</a></li>
3233
<li><a href='#displayable'>displayable</a></li>
3334
<li><a href='#color-spaces'>dlab</a></li>
3435
<li><a href='#color-spaces'>dlch</a></li>
@@ -1097,7 +1098,7 @@ These methods are concerned to finding the [distance between two colors](https:/
10971098

10981099
Returns a [Euclidean distance](https://en.wikipedia.org/wiki/Color_difference#Euclidean) function in a certain color space.
10991100

1100-
You can optionally assign different weights to the channels in the color space. See, for example, the [Kotsarenko/Ramos distance](#differenceKotsarenkoRamos).
1101+
You can optionally assign different weights to the channels in the color space. See, for example, the [Kotsarenko/Ramos distance](#differenceKotsarenkoRamos) or [ΔE<sub>ITP</sub>](#differenceItp).
11011102

11021103
The default weights `[1, 1, 1, 0]` mean that the _alpha_, which is the fourth channel in all the color spaces Culori defines, is not taken into account. Send `[1, 1, 1, 1]` as the weights to include it in the computation.
11031104

@@ -1175,6 +1176,12 @@ Computes the [DIN99o][din99ode] ΔE\*<sub>99o</sub> color difference between the
11751176

11761177
Computes the [Kotsarenko/Ramos][kotsarekno-ramos] color difference between the colors _a_ and _b_. This is a weighted Euclidean distance in the `yiq` color space.
11771178

1179+
<a id="differenceItp" href="#differenceItp">#</a> **differenceItp**()
1180+
1181+
<span aria-label='Source:'>☞</span> [src/difference.js]({{codebase}}/src/difference.js)
1182+
1183+
Computes the [ΔE<sub>ITP</sub>][eitp-difference] color difference metric between the colors _a_ and _b_. This is a weighted Euclidean distance in the `itp` color space, scaled by a factor of 720 so that a the just-noticeable difference (<abbr>JND</abbr>) corresponds to a value of 1.
1184+
11781185
### Nearest color(s)
11791186

11801187
<a id="nearest" href="#nearest">#</a> **nearest**(_colors_, _metric = differenceEuclidean()_, _accessor = identity_) → _function(color, n = 1, τ = Infinity)_
@@ -1898,3 +1905,4 @@ __convertYiqToRgb__(_color_) → _color_ | `yiq` → `rgb`
18981905
[kotsarekno-ramos]: http://www.progmat.uaem.mx:8080/artVol2Num2/Articulo3Vol2Num2.pdf
18991906
[din99ode]: https://de.wikipedia.org/wiki/DIN99-Farbraum#Farbabstandsformel
19001907
[midpoint]: https://github.com/w3c/csswg-drafts/issues/3935
1908+
[eitp-difference]: https://www.itu.int/rec/R-REC-BT.2124/en

docs/color-spaces.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,8 @@ Serialized as `color(--ictcp i t p)`, with the `none` keyword for any missing co
458458

459459
Does not have gamut limits.
460460

461+
The `itp` color space is the basis of the [ΔE<sub>ITP</sub> color difference](/api/#differenceItp) metric defined in _Objective metric for the assessment of the potential visibility of colour differences in television_ ([Rec. ITU-R BT.2124](https://www.itu.int/rec/R-REC-BT.2124/en)).
462+
461463
### Cubehelix
462464

463465
[The Cubehelix color scheme](https://www.mrao.cam.ac.uk/~dag/CUBEHELIX/) was described by Dave Green in this paper:

docs/resources.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ _Does your product/project use Culori? Create a PR and add yourself to this list
3535

3636
### Specifications
3737

38-
- [CSS Color Module Level 4](https://drafts.csswg.org/css-color-4/)
39-
- [CSS Color Module Level 5](https://drafts.csswg.org/css-color-5/)
40-
- [CSS Color HDR Module Level 1](https://drafts.csswg.org/css-color-hdr/)
38+
- [CSS Color Module Level 4](https://drafts.csswg.org/css-color-4/) [[changelog](https://github.com/w3c/csswg-drafts/commits/main/css-color-4)]
39+
- [CSS Color Module Level 5](https://drafts.csswg.org/css-color-5/) [[changelog](https://github.com/w3c/csswg-drafts/commits/main/css-color-5)]
40+
- [CSS Color HDR Module Level 1](https://drafts.csswg.org/css-color-hdr/) [[changelog](https://github.com/w3c/csswg-drafts/commits/main/css-color-hdr)]
4141

4242
### Websites
4343

src/difference.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,14 @@ const differenceHyab = () => {
292292
const differenceKotsarenkoRamos = () =>
293293
differenceEuclidean('yiq', [0.5053, 0.299, 0.1957]);
294294

295+
/*
296+
ΔE_ITP, as defined in Rec. ITU-R BT.2124:
297+
298+
https://www.itu.int/rec/R-REC-BT.2124/en
299+
*/
300+
const differenceItp = () =>
301+
differenceEuclidean('itp', [518400, 129600, 518400]);
302+
295303
export {
296304
differenceHueChroma,
297305
differenceHueSaturation,
@@ -302,5 +310,6 @@ export {
302310
differenceCiede2000,
303311
differenceCmc,
304312
differenceHyab,
305-
differenceKotsarenkoRamos
313+
differenceKotsarenkoRamos,
314+
differenceItp
306315
};

src/index-fn.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ export {
118118
differenceHueSaturation,
119119
differenceHueChroma,
120120
differenceHueNaive,
121-
differenceKotsarenkoRamos
121+
differenceKotsarenkoRamos,
122+
differenceItp
122123
} from './difference.js';
123124

124125
export {

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ export {
119119
differenceHueSaturation,
120120
differenceHueChroma,
121121
differenceHueNaive,
122-
differenceKotsarenkoRamos
122+
differenceKotsarenkoRamos,
123+
differenceItp
123124
} from './difference.js';
124125

125126
export {

test/api.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ const API_FULL = [
9393
'differenceHueSaturation',
9494
'differenceHyab',
9595
'differenceKotsarenkoRamos',
96+
'differenceItp',
9697
'displayable',
9798
'dlab',
9899
'dlch',
@@ -364,6 +365,7 @@ const API_FN = [
364365
'differenceHueSaturation',
365366
'differenceHyab',
366367
'differenceKotsarenkoRamos',
368+
'differenceItp',
367369
'displayable',
368370
'easingGamma',
369371
'easingInOutSine',

test/difference.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
differenceCmc,
88
differenceHyab,
99
differenceKotsarenkoRamos,
10+
differenceItp,
1011
rgb,
1112
lab65,
1213
round,
@@ -187,3 +188,8 @@ tape('differenceHyab', t => {
187188
t.equal(differenceHyab()('red', 'green'), 139.92805737622862);
188189
t.end();
189190
});
191+
192+
tape('differenceItp', t => {
193+
t.equal(differenceItp()('red', 'green'), 238.28868759957626);
194+
t.end();
195+
});

0 commit comments

Comments
 (0)