dcmjs 0.52.0 → 0.52.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/dcmjs.es.js +116 -39
- package/build/dcmjs.es.js.map +1 -1
- package/build/dcmjs.js +116 -39
- package/build/dcmjs.js.map +1 -1
- package/build/dcmjs.min.js +1 -1
- package/build/dcmjs.min.js.map +1 -1
- package/package.json +1 -1
package/build/dcmjs.js
CHANGED
|
@@ -13344,25 +13344,65 @@
|
|
|
13344
13344
|
//
|
|
13345
13345
|
// Handle DICOM and CIELAB colors
|
|
13346
13346
|
// based on:
|
|
13347
|
-
// https://github.com/
|
|
13347
|
+
// https://github.com/DCMTK/dcmtk/blob/88105877c3b610e23fc9422ba6a84af85552f5dd/dcmiod/libsrc/cielabutil.cc
|
|
13348
13348
|
//
|
|
13349
13349
|
// RGB here refers to sRGB 0-1 per component.
|
|
13350
13350
|
// dicomlab is CIELAB values as defined in the dicom standard
|
|
13351
|
-
// XYZ is CIEXYZ convention
|
|
13352
|
-
//
|
|
13353
|
-
// TODO: needs a test suite
|
|
13354
|
-
// TODO: only dicomlab2RGB tested on real data
|
|
13351
|
+
// XYZ is CIEXYZ convention, relative to the D50 white point (ICC PCS)
|
|
13355
13352
|
//
|
|
13353
|
+
// DICOM encodes CIELab values in the same way as the ICC Profile Connection
|
|
13354
|
+
// Space (PCS, see PS3.3 C.10.7.1.1), i.e. relative to the D50 illuminant,
|
|
13355
|
+
// whereas the native white point of sRGB is D65. The conversions below
|
|
13356
|
+
// therefore chromatically adapt between the two using the linear Bradford
|
|
13357
|
+
// transform. Matrices and constants are those of the CSS Color Module Level 4
|
|
13358
|
+
// sample code (https://www.w3.org/TR/css-color-4/#color-conversion-code).
|
|
13356
13359
|
//
|
|
13360
|
+
|
|
13361
|
+
// White points, defined by their 4-figure CIE x,y chromaticities.
|
|
13362
|
+
// D50 is intentionally [0.96430, 1, 0.82510] and not the ICC.1 PCS illuminant
|
|
13363
|
+
// [0.9642, 1, 0.8249]: this matches DCMTK, highdicom and CSS Color 4, and
|
|
13364
|
+
// encodes sRGB white as exactly 0x8080 in a* and b*.
|
|
13365
|
+
var D50_WHITEPOINT_XYZ = [0.3457 / 0.3585, 1.0, (1.0 - 0.3457 - 0.3585) / 0.3585];
|
|
13366
|
+
var D65_WHITEPOINT_XYZ = [0.3127 / 0.329, 1.0, (1.0 - 0.3127 - 0.329) / 0.329];
|
|
13367
|
+
function clamp01(n) {
|
|
13368
|
+
return Math.min(1.0, Math.max(0.0, n));
|
|
13369
|
+
}
|
|
13370
|
+
|
|
13371
|
+
// Rounds to the nearest integer in [0, max]; NaN (invalid input) gives 0
|
|
13372
|
+
function roundClamp(n, max) {
|
|
13373
|
+
if (!(n >= 0.0)) {
|
|
13374
|
+
return 0;
|
|
13375
|
+
}
|
|
13376
|
+
if (n > max) {
|
|
13377
|
+
return max;
|
|
13378
|
+
}
|
|
13379
|
+
return Math.floor(n + 0.5);
|
|
13380
|
+
}
|
|
13357
13381
|
var Colors = /*#__PURE__*/function () {
|
|
13358
13382
|
function Colors() {
|
|
13359
13383
|
_classCallCheck(this, Colors);
|
|
13360
13384
|
}
|
|
13361
13385
|
return _createClass(Colors, null, [{
|
|
13386
|
+
key: "d50WhitePointXYZ",
|
|
13387
|
+
value:
|
|
13388
|
+
/**
|
|
13389
|
+
* White point of the D50 illuminant (ICC PCS), the reference white of
|
|
13390
|
+
* DICOM CIELab. Use this white with the XYZ values of rgb2XYZ, xyz2RGB,
|
|
13391
|
+
* lab2XYZ and xyz2LAB.
|
|
13392
|
+
*/
|
|
13393
|
+
function d50WhitePointXYZ() {
|
|
13394
|
+
return [].concat(D50_WHITEPOINT_XYZ);
|
|
13395
|
+
}
|
|
13396
|
+
|
|
13397
|
+
/**
|
|
13398
|
+
* White point of the D65 illuminant, the native white of sRGB. No
|
|
13399
|
+
* conversion in this class uses it. Do not combine it with the XYZ
|
|
13400
|
+
* values of this class, which are relative to D50.
|
|
13401
|
+
*/
|
|
13402
|
+
}, {
|
|
13362
13403
|
key: "d65WhitePointXYZ",
|
|
13363
13404
|
value: function d65WhitePointXYZ() {
|
|
13364
|
-
|
|
13365
|
-
return [0.950456, 1.0, 1.088754];
|
|
13405
|
+
return [].concat(D65_WHITEPOINT_XYZ);
|
|
13366
13406
|
}
|
|
13367
13407
|
}, {
|
|
13368
13408
|
key: "dicomlab2RGB",
|
|
@@ -13374,6 +13414,26 @@
|
|
|
13374
13414
|
value: function rgb2DICOMLAB(rgb) {
|
|
13375
13415
|
return Colors.lab2DICOMLAB(Colors.rgb2LAB(rgb));
|
|
13376
13416
|
}
|
|
13417
|
+
|
|
13418
|
+
// 16 bit DICOM CIELab -> 8 bit sRGB, rounded and clamped
|
|
13419
|
+
}, {
|
|
13420
|
+
key: "dicomlab2RGB8",
|
|
13421
|
+
value: function dicomlab2RGB8(dicomlab) {
|
|
13422
|
+
return Colors.dicomlab2RGB(dicomlab).map(function (n) {
|
|
13423
|
+
return roundClamp(n * 255.0, 255);
|
|
13424
|
+
});
|
|
13425
|
+
}
|
|
13426
|
+
|
|
13427
|
+
// 8 bit sRGB (array or typed array) -> 16 bit DICOM CIELab, rounded and clamped
|
|
13428
|
+
}, {
|
|
13429
|
+
key: "rgb82DICOMLAB",
|
|
13430
|
+
value: function rgb82DICOMLAB(rgb) {
|
|
13431
|
+
return Colors.rgb2DICOMLAB(Array.from(rgb, function (n) {
|
|
13432
|
+
return n / 255.0;
|
|
13433
|
+
})).map(function (n) {
|
|
13434
|
+
return roundClamp(n, 65535);
|
|
13435
|
+
});
|
|
13436
|
+
}
|
|
13377
13437
|
}, {
|
|
13378
13438
|
key: "dicomlab2LAB",
|
|
13379
13439
|
value: function dicomlab2LAB(dicomlab) {
|
|
@@ -13402,7 +13462,8 @@
|
|
|
13402
13462
|
}, {
|
|
13403
13463
|
key: "gammaCorrection",
|
|
13404
13464
|
value: function gammaCorrection(n) {
|
|
13405
|
-
|
|
13465
|
+
// sRGB transfer function (IEC 61966-2-1), linear to gamma-encoded
|
|
13466
|
+
if (n <= 0.0031308) {
|
|
13406
13467
|
return 12.92 * n;
|
|
13407
13468
|
} else {
|
|
13408
13469
|
return 1.055 * Math.pow(n, 1 / 2.4) - 0.055;
|
|
@@ -13411,27 +13472,39 @@
|
|
|
13411
13472
|
}, {
|
|
13412
13473
|
key: "invGammaCorrection",
|
|
13413
13474
|
value: function invGammaCorrection(n) {
|
|
13414
|
-
|
|
13475
|
+
// sRGB transfer function (IEC 61966-2-1), gamma-encoded to linear
|
|
13476
|
+
if (n <= 0.04045) {
|
|
13415
13477
|
return n / 12.92;
|
|
13416
13478
|
} else {
|
|
13417
13479
|
return Math.pow((n + 0.055) / 1.055, 2.4);
|
|
13418
13480
|
}
|
|
13419
13481
|
}
|
|
13482
|
+
|
|
13483
|
+
// sRGB -> CIE XYZ relative to D50, as DICOM CIELab requires (not D65)
|
|
13420
13484
|
}, {
|
|
13421
13485
|
key: "rgb2XYZ",
|
|
13422
13486
|
value: function rgb2XYZ(rgb) {
|
|
13487
|
+
// sRGB to linear RGB
|
|
13423
13488
|
var R = Colors.invGammaCorrection(rgb[0]);
|
|
13424
13489
|
var G = Colors.invGammaCorrection(rgb[1]);
|
|
13425
13490
|
var B = Colors.invGammaCorrection(rgb[2]);
|
|
13426
|
-
|
|
13491
|
+
|
|
13492
|
+
// linear RGB to CIE XYZ (D65)
|
|
13493
|
+
var X65 = 506752.0 / 1228815.0 * R + 87881.0 / 245763.0 * G + 12673.0 / 70218.0 * B;
|
|
13494
|
+
var Y65 = 87098.0 / 409605.0 * R + 175762.0 / 245763.0 * G + 12673.0 / 175545.0 * B;
|
|
13495
|
+
var Z65 = 7918.0 / 409605.0 * R + 87881.0 / 737289.0 * G + 1001167.0 / 1053270.0 * B;
|
|
13496
|
+
|
|
13497
|
+
// chromatic adaptation D65 to D50 (linear Bradford)
|
|
13498
|
+
return [1.0479297925449969 * X65 + 0.022946870601609652 * Y65 - 0.05019226628920524 * Z65, 0.02962780877005599 * X65 + 0.9904344267538799 * Y65 - 0.017073799063418826 * Z65, -0.009243040646204504 * X65 + 0.015055191490298152 * Y65 + 0.7518742814281371 * Z65];
|
|
13427
13499
|
}
|
|
13500
|
+
|
|
13501
|
+
// CIE XYZ relative to D50 -> CIELab
|
|
13428
13502
|
}, {
|
|
13429
13503
|
key: "xyz2LAB",
|
|
13430
13504
|
value: function xyz2LAB(xyz) {
|
|
13431
|
-
var
|
|
13432
|
-
var
|
|
13433
|
-
var
|
|
13434
|
-
var Z = xyz[2] / whitePoint[2];
|
|
13505
|
+
var X = xyz[0] / D50_WHITEPOINT_XYZ[0];
|
|
13506
|
+
var Y = xyz[1] / D50_WHITEPOINT_XYZ[1];
|
|
13507
|
+
var Z = xyz[2] / D50_WHITEPOINT_XYZ[2];
|
|
13435
13508
|
X = Colors.labf(X);
|
|
13436
13509
|
Y = Colors.labf(Y);
|
|
13437
13510
|
Z = Colors.labf(Z);
|
|
@@ -13442,50 +13515,58 @@
|
|
|
13442
13515
|
value: function lab2RGB(lab) {
|
|
13443
13516
|
return Colors.xyz2RGB(Colors.lab2XYZ(lab));
|
|
13444
13517
|
}
|
|
13518
|
+
|
|
13519
|
+
// CIELab -> CIE XYZ relative to D50
|
|
13445
13520
|
}, {
|
|
13446
13521
|
key: "lab2XYZ",
|
|
13447
13522
|
value: function lab2XYZ(lab) {
|
|
13448
13523
|
var L = (lab[0] + 16) / 116;
|
|
13449
13524
|
var a = L + lab[1] / 500;
|
|
13450
13525
|
var b = L - lab[2] / 200;
|
|
13451
|
-
|
|
13452
|
-
return [whitePoint[0] * Colors.labfInv(a), whitePoint[1] * Colors.labfInv(L), whitePoint[2] * Colors.labfInv(b)];
|
|
13526
|
+
return [D50_WHITEPOINT_XYZ[0] * Colors.labfInv(a), D50_WHITEPOINT_XYZ[1] * Colors.labfInv(L), D50_WHITEPOINT_XYZ[2] * Colors.labfInv(b)];
|
|
13453
13527
|
}
|
|
13528
|
+
|
|
13529
|
+
// CIE XYZ relative to D50 -> sRGB, clipped per channel to [0, 1]
|
|
13454
13530
|
}, {
|
|
13455
13531
|
key: "xyz2RGB",
|
|
13456
13532
|
value: function xyz2RGB(xyz) {
|
|
13457
|
-
var
|
|
13458
|
-
|
|
13459
|
-
|
|
13533
|
+
var _xyz = _slicedToArray(xyz, 3),
|
|
13534
|
+
X = _xyz[0],
|
|
13535
|
+
Y = _xyz[1],
|
|
13536
|
+
Z = _xyz[2];
|
|
13460
13537
|
|
|
13461
|
-
|
|
13462
|
-
var
|
|
13463
|
-
|
|
13464
|
-
|
|
13465
|
-
R1 -= minimumComponent;
|
|
13466
|
-
G1 -= minimumComponent;
|
|
13467
|
-
B1 -= minimumComponent;
|
|
13468
|
-
}
|
|
13538
|
+
// chromatic adaptation D50 to D65 (linear Bradford)
|
|
13539
|
+
var X65 = 0.955473421488075 * X - 0.02309845494876471 * Y + 0.06325924320057072 * Z;
|
|
13540
|
+
var Y65 = -0.0283697093338637 * X + 1.0099953980813041 * Y + 0.021041441191917323 * Z;
|
|
13541
|
+
var Z65 = 0.012314014864481998 * X - 0.020507649298898964 * Y + 1.330365926242124 * Z;
|
|
13469
13542
|
|
|
13470
|
-
|
|
13471
|
-
|
|
13543
|
+
// CIE XYZ (D65) to linear RGB
|
|
13544
|
+
var R1 = 12831.0 / 3959.0 * X65 - 329.0 / 214.0 * Y65 - 1974.0 / 3959.0 * Z65;
|
|
13545
|
+
var G1 = -851781 / 878810.0 * X65 + 1648619.0 / 878810.0 * Y65 + 36519.0 / 878810.0 * Z65;
|
|
13546
|
+
var B1 = 705.0 / 12673.0 * X65 - 2585.0 / 12673.0 * Y65 + 705.0 / 667.0 * Z65;
|
|
13547
|
+
|
|
13548
|
+
// Clip to the sRGB gamut (also makes sure that gamma encoding is
|
|
13549
|
+
// well-defined), then transform from linear RGB to sRGB
|
|
13550
|
+
return [Colors.gammaCorrection(clamp01(R1)), Colors.gammaCorrection(clamp01(G1)), Colors.gammaCorrection(clamp01(B1))];
|
|
13472
13551
|
}
|
|
13473
13552
|
}, {
|
|
13474
13553
|
key: "labf",
|
|
13475
13554
|
value: function labf(n) {
|
|
13476
|
-
|
|
13477
|
-
|
|
13555
|
+
// epsilon = (6/29)^3 = 216/24389, kappa = (29/3)^3 = 24389/27
|
|
13556
|
+
if (n > 216.0 / 24389.0) {
|
|
13557
|
+
return Math.cbrt(n);
|
|
13478
13558
|
} else {
|
|
13479
|
-
return
|
|
13559
|
+
return (24389.0 / 27.0 * n + 16.0) / 116.0;
|
|
13480
13560
|
}
|
|
13481
13561
|
}
|
|
13482
13562
|
}, {
|
|
13483
13563
|
key: "labfInv",
|
|
13484
13564
|
value: function labfInv(n) {
|
|
13485
|
-
|
|
13565
|
+
// n > 6/29 <=> n^3 > epsilon
|
|
13566
|
+
if (n > 6.0 / 29.0) {
|
|
13486
13567
|
return n * n * n;
|
|
13487
13568
|
} else {
|
|
13488
|
-
return
|
|
13569
|
+
return (116.0 * n - 16.0) / (24389.0 / 27.0);
|
|
13489
13570
|
}
|
|
13490
13571
|
}
|
|
13491
13572
|
}]);
|
|
@@ -24346,12 +24427,8 @@
|
|
|
24346
24427
|
CORNERSTONE_3D_TAG: CORNERSTONE_3D_TAG
|
|
24347
24428
|
};
|
|
24348
24429
|
|
|
24349
|
-
// TODO: Is there a better name for this? RGBAInt?
|
|
24350
|
-
// Should we move it to Colors.js
|
|
24351
24430
|
function dicomlab2RGBA(cielab) {
|
|
24352
|
-
var rgba = Colors.
|
|
24353
|
-
return Math.round(x * 255);
|
|
24354
|
-
});
|
|
24431
|
+
var rgba = Colors.dicomlab2RGB8(cielab);
|
|
24355
24432
|
rgba.push(255);
|
|
24356
24433
|
return rgba;
|
|
24357
24434
|
}
|