Debian Codegraph @

node/colorjs.io/src/deltaE/deltaEITP.js

raw
1 import ictcp from "../spaces/ictcp.js";
2 import getColor from "../getColor.js";
3
4 /**
5 * Delta E in ICtCp space,
6 * which the ITU calls Delta E ITP, which is shorter.
7 * Formulae from ITU Rec. ITU-R BT.2124-0
8 * @param {import("../types.js").ColorTypes} color
9 * @param {import("../types.js").ColorTypes} sample
10 * @returns {number}
11 */
12 export default function (color, sample) {
13 [color, sample] = getColor([color, sample]);
14
15 // Given this color as the reference
16 // and a sample,
17 // calculate deltaE in ICtCp
18 // which is simply the Euclidean distance
19
20 let [I1, T1, P1] = ictcp.from(color);
21 let [I2, T2, P2] = ictcp.from(sample);
22
23 // the 0.25 factor is to undo the encoding scaling in Ct
24 // the 720 is so that 1 deltaE = 1 JND
25 // per ITU-R BT.2124-0 p.3
26
27 return 720 * Math.sqrt((I1 - I2) ** 2 + 0.25 * (T1 - T2) ** 2 + (P1 - P2) ** 2);
28 }