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