dwv 0.37.0-beta.3 → 0.37.0-beta.4
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/dev/bench/bench.html +94 -0
- package/dev/bench/bench.js +316 -0
- package/dev/bench/benchFunctionRunner.js +83 -0
- package/dev/bench/dataRunner.js +171 -0
- package/dev/bench/gui.js +184 -0
- package/dev/bench/listen.js +70 -0
- package/dev/bench/parsers/dwv-current.html +45 -0
- package/dev/bench/parsers/dwv-previous.html +45 -0
- package/dev/dicom/binaryPixGenerator.js +108 -0
- package/dev/dicom/dicomGenerator.js +215 -0
- package/dev/dicom/filePixGenerator.js +96 -0
- package/dev/dicom/gradSquarePixGenerator.js +107 -0
- package/dev/dicom/mprPixGenerator.js +247 -0
- package/dev/dicom/pages/anonymiser.html +86 -0
- package/dev/dicom/pages/anonymiser.js +154 -0
- package/dev/dicom/pages/generator.html +92 -0
- package/dev/dicom/pages/generator.js +329 -0
- package/dev/dicom/pages/synthetic-data.html +19 -0
- package/dev/dicom/pages/synthetic-data.js +164 -0
- package/dev/dicom/squarePixGenerator.js +233 -0
- package/dev/favicon.ico +0 -0
- package/dev/image/pages/colourmaps.html +16 -0
- package/dev/image/pages/colourmaps.js +65 -0
- package/dev/index.html +37 -0
- package/dev/pacs/dcmweb.html +80 -0
- package/dev/pacs/dcmweb.js +577 -0
- package/dev/pacs/images/acute_leukemia.png +0 -0
- package/dev/pacs/images/babymri-dcmdir.png +0 -0
- package/dev/pacs/images/babymri-rect.png +0 -0
- package/dev/pacs/images/babymri-zip.png +0 -0
- package/dev/pacs/images/babymri.png +0 -0
- package/dev/pacs/images/brainmri-png.png +0 -0
- package/dev/pacs/images/brainpet-jpg.png +0 -0
- package/dev/pacs/images/cerebrix.png +0 -0
- package/dev/pacs/images/goudurix.png +0 -0
- package/dev/pacs/images/multiframe-test1.png +0 -0
- package/dev/pacs/images/toutatix.png +0 -0
- package/dev/pacs/images/us.png +0 -0
- package/dev/pacs/index.html +97 -0
- package/dev/pacs/index.js +287 -0
- package/dev/pacs/overlays.js +51 -0
- package/dev/pacs/viewer.html +401 -0
- package/dev/pacs/viewer.js +1275 -0
- package/dev/pacs/viewer.rendertest.js +96 -0
- package/dev/pacs/viewer.ui.annot.js +607 -0
- package/dev/pacs/viewer.ui.brush.js +181 -0
- package/dev/pacs/viewer.ui.datatable.js +674 -0
- package/dev/pacs/viewer.ui.draw.js +141 -0
- package/dev/pacs/viewer.ui.icons.js +88 -0
- package/dev/pacs/viewer.ui.js +198 -0
- package/dev/pacs/viewer.ui.segment.js +1263 -0
- package/dev/visual/appgui.js +125 -0
- package/dev/visual/images/dicompyler-ct.0.jpg +0 -0
- package/dev/visual/images/gdcm-CR-MONO1-10-chest.jpg +0 -0
- package/dev/visual/images/gdcm-CT-MONO2-8-abdo.jpg +0 -0
- package/dev/visual/images/gdcm-US-RGB-8-epicard.jpg +0 -0
- package/dev/visual/images/gdcm-US-RGB-8-esopecho.jpg +0 -0
- package/dev/visual/images/leadtools-8BitsJpegLossyGrayScale.jpg +0 -0
- package/dev/visual/images/leadtools-flowers-16-mono2-rle.jpg +0 -0
- package/dev/visual/images/leadtools-flowers-8-mono2-rle.jpg +0 -0
- package/dev/visual/images/nema-ct1_j2ki.jpg +0 -0
- package/dev/visual/images/nema-ct1_jpll.jpg +0 -0
- package/dev/visual/images/nema-mr1_jply.jpg +0 -0
- package/dev/visual/images/nema-nm1_j2kr.jpg +0 -0
- package/dev/visual/images/nema-nm1_jpll.jpg +0 -0
- package/dev/visual/images/nema-nm1_jply.jpg +0 -0
- package/dev/visual/images/nema-us1_j2ki.jpg +0 -0
- package/dev/visual/images/nema-vl2_j2kr.jpg +0 -0
- package/dev/visual/images/osirix-cerebrix.jpg +0 -0
- package/dev/visual/images/osirix-goudurix.jpg +0 -0
- package/dev/visual/images/osirix-toutatix-100.jpg +0 -0
- package/dev/visual/index-jpeg.js +104 -0
- package/dev/visual/index-jpeg2000.js +103 -0
- package/dev/visual/index-rle.js +70 -0
- package/dev/visual/index.html +20 -0
- package/dev/visual/index.js +123 -0
- package/dev/visual/style.css +37 -0
- package/dist/assets/workers/jpeg2000.worker.min.js.map +1 -1
- package/dist/assets/workers/labeling.worker.min.js +1 -1
- package/dist/assets/workers/labeling.worker.min.js.map +1 -1
- package/dist/assets/workers/resampling.worker.min.js +1 -1
- package/dist/assets/workers/resampling.worker.min.js.map +1 -1
- package/dist/dwv.d.ts +1048 -198
- package/dist/dwv.min.js +1 -1
- package/dist/dwv.min.js.map +1 -1
- package/dist/dwv.node.min.js +1 -1
- package/dist/dwv.node.min.js.map +1 -1
- package/package.json +11 -11
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import {getImageDataData} from './dicomGenerator.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* FilePixGenerator: generates pixel data from file(s).
|
|
5
|
+
*/
|
|
6
|
+
export class FilePixGenerator {
|
|
7
|
+
|
|
8
|
+
#numberOfColumns;
|
|
9
|
+
#numberOfRows;
|
|
10
|
+
|
|
11
|
+
#isRGB;
|
|
12
|
+
|
|
13
|
+
#images;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {object} options The generator options.
|
|
17
|
+
*/
|
|
18
|
+
constructor(options) {
|
|
19
|
+
this.#numberOfColumns = options.numberOfColumns;
|
|
20
|
+
this.#numberOfRows = options.numberOfRows;
|
|
21
|
+
this.#isRGB = options.photometricInterpretation === 'RGB';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
setImages(imgs) {
|
|
25
|
+
// check sizes
|
|
26
|
+
let img;
|
|
27
|
+
for (let i = 0; i < imgs.length; ++i) {
|
|
28
|
+
img = imgs[i];
|
|
29
|
+
if (img.width !== this.#numberOfColumns) {
|
|
30
|
+
throw new Error(`Image width mismatch: ${
|
|
31
|
+
img.width }!=${this.#numberOfColumns}`);
|
|
32
|
+
}
|
|
33
|
+
if (img.height !== this.#numberOfRows) {
|
|
34
|
+
throw new Error(`Image height mismatch: ${
|
|
35
|
+
img.height }!=${this.#numberOfRows}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// store
|
|
39
|
+
this.#images = imgs;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @param {number[]} pixelBuffer The buffer.
|
|
44
|
+
* @param {number} sliceNumber The slice index.
|
|
45
|
+
*/
|
|
46
|
+
generate(pixelBuffer, sliceNumber) {
|
|
47
|
+
let image;
|
|
48
|
+
if (sliceNumber < this.images.length) {
|
|
49
|
+
image = this.#images[sliceNumber];
|
|
50
|
+
} else {
|
|
51
|
+
image = this.#images[0];
|
|
52
|
+
}
|
|
53
|
+
// get the image data
|
|
54
|
+
const imageData = getImageDataData(image);
|
|
55
|
+
// extract fist component for the pixelBuffer
|
|
56
|
+
const dataLen = imageData.length;
|
|
57
|
+
let j = 0;
|
|
58
|
+
for (let i = 0; i < dataLen; i += 4) {
|
|
59
|
+
pixelBuffer[j] = imageData[i];
|
|
60
|
+
j += 1;
|
|
61
|
+
if (this.#isRGB) {
|
|
62
|
+
pixelBuffer[j + 1] = imageData[i + 1];
|
|
63
|
+
pixelBuffer[j + 2] = imageData[i + 2];
|
|
64
|
+
j += 2;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Check tags are coherent with image size.
|
|
72
|
+
*
|
|
73
|
+
* @param {object} tags The tags to check.
|
|
74
|
+
* @param {object} image The associated image.
|
|
75
|
+
* @returns {boolean} True if the tags are ok.
|
|
76
|
+
*/
|
|
77
|
+
export function fileCheckTags(tags, image) {
|
|
78
|
+
/**
|
|
79
|
+
* @param {number} value The value to check.
|
|
80
|
+
* @returns {number} The expected value.
|
|
81
|
+
*/
|
|
82
|
+
function getExpectedSize(value) {
|
|
83
|
+
return value;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
let needUpdate = false;
|
|
87
|
+
if (tags.Columns !== getExpectedSize(image.width)) {
|
|
88
|
+
tags.Columns = getExpectedSize(image.width);
|
|
89
|
+
needUpdate = true;
|
|
90
|
+
}
|
|
91
|
+
if (tags.Rows !== getExpectedSize(image.height)) {
|
|
92
|
+
tags.Rows = getExpectedSize(image.height);
|
|
93
|
+
needUpdate = true;
|
|
94
|
+
}
|
|
95
|
+
return needUpdate;
|
|
96
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GradSquarePixGenerator: generates pixel data as a small gradient square.
|
|
3
|
+
*/
|
|
4
|
+
export class GradSquarePixGenerator {
|
|
5
|
+
|
|
6
|
+
#numberOfColumns;
|
|
7
|
+
#numberOfRows;
|
|
8
|
+
#numberOfSamples;
|
|
9
|
+
#numberOfColourPlanes;
|
|
10
|
+
|
|
11
|
+
#isRGB;
|
|
12
|
+
|
|
13
|
+
#minI;
|
|
14
|
+
#minJ;
|
|
15
|
+
#maxI;
|
|
16
|
+
#maxJ;
|
|
17
|
+
|
|
18
|
+
#background = 0;
|
|
19
|
+
#maxValue = 255;
|
|
20
|
+
#maxNoBounds = 1;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param {object} options The generator options.
|
|
24
|
+
*/
|
|
25
|
+
constructor(options) {
|
|
26
|
+
this.#numberOfColumns = options.numberOfColumns;
|
|
27
|
+
this.#numberOfRows = options.numberOfRows;
|
|
28
|
+
this.#numberOfSamples = options.numberOfSamples;
|
|
29
|
+
this.#numberOfColourPlanes = options.numberOfColourPlanes;
|
|
30
|
+
|
|
31
|
+
this.#isRGB = options.photometricInterpretation === 'RGB';
|
|
32
|
+
|
|
33
|
+
// full grad square
|
|
34
|
+
const borderI = 0;
|
|
35
|
+
const borderJ = 0;
|
|
36
|
+
// ~centered grad square
|
|
37
|
+
// const borderI = Math.ceil(numberOfColumns * 0.25);
|
|
38
|
+
// const borderJ = Math.ceil(numberOfRows * 0.25);
|
|
39
|
+
|
|
40
|
+
this.#minI = borderI;
|
|
41
|
+
this.#minJ = borderJ;
|
|
42
|
+
this.#maxI = this.#numberOfColumns - borderI;
|
|
43
|
+
this.#maxJ = this.#numberOfRows - borderJ;
|
|
44
|
+
|
|
45
|
+
const maxK = this.#maxI;
|
|
46
|
+
this.#maxNoBounds =
|
|
47
|
+
this.#getValue(this.#maxI, this.#maxJ, maxK) / this.#maxValue;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @param {number[]} pixelBuffer The buffer.
|
|
52
|
+
* @param {number} sliceNumber The slice index.
|
|
53
|
+
*/
|
|
54
|
+
generate(pixelBuffer, sliceNumber) {
|
|
55
|
+
const getFunc = this.#isRGB ? this.#getRGB : this.#getValue;
|
|
56
|
+
|
|
57
|
+
let offset = 0;
|
|
58
|
+
for (let c = 0; c < this.#numberOfColourPlanes; ++c) {
|
|
59
|
+
for (let j = 0; j < this.#numberOfRows; ++j) {
|
|
60
|
+
for (let i = 0; i < this.#numberOfColumns; ++i) {
|
|
61
|
+
for (let s = 0; s < this.#numberOfSamples; ++s) {
|
|
62
|
+
if (this.#numberOfColourPlanes !== 1) {
|
|
63
|
+
pixelBuffer[offset] = getFunc(i, j, sliceNumber)[c];
|
|
64
|
+
} else {
|
|
65
|
+
pixelBuffer[offset] = getFunc(i, j, sliceNumber)[s];
|
|
66
|
+
}
|
|
67
|
+
++offset;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Get a simple value.
|
|
76
|
+
*
|
|
77
|
+
* @param {number} i The column index.
|
|
78
|
+
* @param {number} j The row index.
|
|
79
|
+
* @param {number} k The slice index.
|
|
80
|
+
* @returns {number[]} The grey value.
|
|
81
|
+
*/
|
|
82
|
+
#getValue = (i, j, k) => {
|
|
83
|
+
let value = this.#background + k * 2;
|
|
84
|
+
const inRange = i >= this.#minI && i <= this.#maxI &&
|
|
85
|
+
j >= this.#minJ && j <= this.#maxJ;
|
|
86
|
+
if (inRange) {
|
|
87
|
+
value += Math.round((i + j) * (this.#maxValue / this.#maxNoBounds));
|
|
88
|
+
}
|
|
89
|
+
return [value];
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Get RGB values.
|
|
94
|
+
*
|
|
95
|
+
* @param {number} i The column index.
|
|
96
|
+
* @param {number} j The row index.
|
|
97
|
+
* @param {number} k The slice index.
|
|
98
|
+
* @returns {number[]} The [R,G,B] values.
|
|
99
|
+
*/
|
|
100
|
+
#getRGB = (i, j, k) => {
|
|
101
|
+
let value = this.#getValue(i, j, k);
|
|
102
|
+
if (value > this.#maxValue) {
|
|
103
|
+
value = 200;
|
|
104
|
+
}
|
|
105
|
+
return [value, 0, 0];
|
|
106
|
+
};
|
|
107
|
+
}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getOrientationName,
|
|
3
|
+
Orientation
|
|
4
|
+
} from '../../src/math/orientation.js';
|
|
5
|
+
|
|
6
|
+
import {getImageDataData} from './dicomGenerator.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* MPRPixGenerator: generates pixel data from file
|
|
10
|
+
* with an input per orientation.
|
|
11
|
+
*/
|
|
12
|
+
export class MPRPixGenerator {
|
|
13
|
+
|
|
14
|
+
#numberOfColumns;
|
|
15
|
+
#numberOfRows;
|
|
16
|
+
#numberOfSlices = 0;
|
|
17
|
+
|
|
18
|
+
#halfNCols;
|
|
19
|
+
#halfNRows;
|
|
20
|
+
#halfNSlices = 0;
|
|
21
|
+
|
|
22
|
+
#isRGB;
|
|
23
|
+
#orientationName;
|
|
24
|
+
|
|
25
|
+
#images = [];
|
|
26
|
+
#buffers = [];
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {object} options The generator options.
|
|
30
|
+
*/
|
|
31
|
+
constructor(options) {
|
|
32
|
+
this.#numberOfColumns = options.numberOfColumns;
|
|
33
|
+
this.#numberOfRows = options.numberOfRows;
|
|
34
|
+
this.#isRGB = options.photometricInterpretation === 'RGB';
|
|
35
|
+
|
|
36
|
+
if (this.#isRGB) {
|
|
37
|
+
throw new Error('The MPRPixGenerator does not support RGB data.');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
this.#halfNCols = this.#numberOfColumns * 0.5;
|
|
41
|
+
this.#halfNRows = this.#numberOfRows * 0.5;
|
|
42
|
+
|
|
43
|
+
this.#orientationName =
|
|
44
|
+
getOrientationName(options.imageOrientationPatient);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
setNumberOfSlices(num) {
|
|
48
|
+
this.#numberOfSlices = num;
|
|
49
|
+
this.#halfNSlices = num * 0.5;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
setImages(imgs) {
|
|
53
|
+
// check sizes
|
|
54
|
+
let img;
|
|
55
|
+
for (let i = 0; i < imgs.length; ++i) {
|
|
56
|
+
img = imgs[i];
|
|
57
|
+
if (img.width !== this.#halfNCols) {
|
|
58
|
+
throw new Error(`Image width mismatch: ${
|
|
59
|
+
img.width }!=${this.#halfNCols}`);
|
|
60
|
+
}
|
|
61
|
+
if (img.height !== this.#halfNRows) {
|
|
62
|
+
throw new Error(`Image height mismatch: ${
|
|
63
|
+
img.height }!=${this.#halfNRows}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// store
|
|
67
|
+
this.#images = imgs;
|
|
68
|
+
// store buffers
|
|
69
|
+
this.#buffers = [];
|
|
70
|
+
for (let i0 = 0; i0 < imgs.length; ++i0) {
|
|
71
|
+
this.#buffers.push(getImageDataData(this.#images[i0]));
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
generate(pixelBuffer, sliceNumber) {
|
|
76
|
+
if (sliceNumber > this.#numberOfSlices) {
|
|
77
|
+
throw new Error(`Cannot generate slice, number is above size: ${
|
|
78
|
+
sliceNumber }, ${this.#numberOfSlices}`);
|
|
79
|
+
}
|
|
80
|
+
if (this.#orientationName === Orientation.Axial) {
|
|
81
|
+
this.#generateAsAxial(pixelBuffer, sliceNumber);
|
|
82
|
+
} else if (this.#orientationName === Orientation.Coronal) {
|
|
83
|
+
this.#generateAsCoronal(pixelBuffer, sliceNumber);
|
|
84
|
+
} else if (this.#orientationName === Orientation.Sagittal) {
|
|
85
|
+
this.#generateAsSagittal(pixelBuffer, sliceNumber);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
#generateAsAxial(pixelBuffer, sliceNumber) {
|
|
90
|
+
// axial
|
|
91
|
+
let offset = 0;
|
|
92
|
+
for (let j0 = 0; j0 < this.#halfNRows; ++j0) {
|
|
93
|
+
for (let i0 = 0; i0 < this.#halfNCols; ++i0) {
|
|
94
|
+
pixelBuffer[offset] = this.#getFunc(Orientation.Axial, i0, j0);
|
|
95
|
+
++offset;
|
|
96
|
+
}
|
|
97
|
+
offset += this.#halfNCols;
|
|
98
|
+
}
|
|
99
|
+
if (sliceNumber < this.#halfNSlices) {
|
|
100
|
+
// coronal
|
|
101
|
+
offset = this.#halfNCols;
|
|
102
|
+
for (let j1 = 0; j1 < this.#numberOfRows; ++j1) {
|
|
103
|
+
for (let i1 = 0; i1 < this.#halfNCols; ++i1) {
|
|
104
|
+
pixelBuffer[offset] = this.#getFunc(
|
|
105
|
+
Orientation.Coronal, i1, (this.#halfNSlices - 1 - sliceNumber));
|
|
106
|
+
++offset;
|
|
107
|
+
}
|
|
108
|
+
offset += this.#halfNCols;
|
|
109
|
+
}
|
|
110
|
+
} else {
|
|
111
|
+
// sagittal
|
|
112
|
+
offset = this.#numberOfColumns * this.#halfNRows;
|
|
113
|
+
for (let j2 = 0; j2 < this.#halfNRows; ++j2) {
|
|
114
|
+
for (let i2 = 0; i2 < this.#numberOfColumns; ++i2) {
|
|
115
|
+
pixelBuffer[offset] = this.#getFunc(
|
|
116
|
+
Orientation.Sagittal, j2, (this.#numberOfSlices - 1 - sliceNumber));
|
|
117
|
+
++offset;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
#generateAsCoronal(pixelBuffer, sliceNumber) {
|
|
124
|
+
// coronal
|
|
125
|
+
let offset = this.#numberOfColumns * this.#halfNRows + this.#halfNCols;
|
|
126
|
+
for (let j0 = 0; j0 < this.#halfNRows; ++j0) {
|
|
127
|
+
for (let i0 = 0; i0 < this.#halfNCols; ++i0) {
|
|
128
|
+
pixelBuffer[offset] = this.#getFunc(Orientation.Coronal, i0, j0);
|
|
129
|
+
++offset;
|
|
130
|
+
}
|
|
131
|
+
offset += this.#halfNCols;
|
|
132
|
+
}
|
|
133
|
+
if (sliceNumber < this.#halfNSlices) {
|
|
134
|
+
// axial
|
|
135
|
+
offset = 0;
|
|
136
|
+
for (let j1 = 0; j1 < this.#numberOfRows; ++j1) {
|
|
137
|
+
for (let i1 = 0; i1 < this.#halfNCols; ++i1) {
|
|
138
|
+
pixelBuffer[offset] = this.#getFunc(
|
|
139
|
+
Orientation.Axial, i1, sliceNumber);
|
|
140
|
+
++offset;
|
|
141
|
+
}
|
|
142
|
+
offset += this.#halfNCols;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
} else {
|
|
146
|
+
// sagittal
|
|
147
|
+
offset = 0;
|
|
148
|
+
for (let j2 = 0; j2 < this.#halfNRows; ++j2) {
|
|
149
|
+
for (let i2 = 0; i2 < this.#numberOfColumns; ++i2) {
|
|
150
|
+
pixelBuffer[offset] = this.#getFunc(
|
|
151
|
+
Orientation.Sagittal, sliceNumber, j2 - 1);
|
|
152
|
+
++offset;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
#generateAsSagittal(pixelBuffer, sliceNumber) {
|
|
159
|
+
// sagittal
|
|
160
|
+
let offset = this.#halfNCols;
|
|
161
|
+
for (let j0 = 0; j0 < this.#halfNRows; ++j0) {
|
|
162
|
+
for (let i0 = 0; i0 < this.#halfNCols; ++i0) {
|
|
163
|
+
pixelBuffer[offset] = this.#getFunc(Orientation.Sagittal, i0, j0);
|
|
164
|
+
++offset;
|
|
165
|
+
}
|
|
166
|
+
offset += this.#halfNCols;
|
|
167
|
+
}
|
|
168
|
+
if (sliceNumber < this.#halfNSlices) {
|
|
169
|
+
// axial
|
|
170
|
+
offset = 0;
|
|
171
|
+
for (let j1 = 0; j1 < this.#numberOfRows; ++j1) {
|
|
172
|
+
for (let i1 = 0; i1 < this.#halfNCols; ++i1) {
|
|
173
|
+
pixelBuffer[offset] = this.#getFunc(
|
|
174
|
+
Orientation.Axial, sliceNumber, i1);
|
|
175
|
+
++offset;
|
|
176
|
+
}
|
|
177
|
+
offset += this.#halfNCols;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
} else {
|
|
181
|
+
// coronal
|
|
182
|
+
offset = this.#numberOfColumns * this.#halfNRows;
|
|
183
|
+
for (let j2 = 0; j2 < this.#halfNRows; ++j2) {
|
|
184
|
+
for (let i2 = 0; i2 < this.#numberOfColumns; ++i2) {
|
|
185
|
+
pixelBuffer[offset] = this.#getFunc(
|
|
186
|
+
Orientation.Coronal, sliceNumber, j2 - 1);
|
|
187
|
+
++offset;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* @param {number} i The column index.
|
|
195
|
+
* @param {number} j The row index.
|
|
196
|
+
* @returns {number} The offset for the given position.
|
|
197
|
+
*/
|
|
198
|
+
#getOffset(i, j) {
|
|
199
|
+
return i + j * this.#halfNCols;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* @param {string} name The image orientation.
|
|
204
|
+
* @param {number} i The column index.
|
|
205
|
+
* @param {number} j The row index.
|
|
206
|
+
* @returns {number} The value at the given position.
|
|
207
|
+
*/
|
|
208
|
+
#getFunc(name, i, j) {
|
|
209
|
+
let imgIdx = 0;
|
|
210
|
+
if (name === Orientation.Axial) {
|
|
211
|
+
imgIdx = 0;
|
|
212
|
+
} else if (name === Orientation.Coronal) {
|
|
213
|
+
imgIdx = 1;
|
|
214
|
+
} else if (name === Orientation.Sagittal) {
|
|
215
|
+
imgIdx = 2;
|
|
216
|
+
}
|
|
217
|
+
return this.#buffers[imgIdx][this.#getOffset(i, j) * 4];
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Check tags are coherent with image size.
|
|
223
|
+
*
|
|
224
|
+
* @param {object} tags The tags to check.
|
|
225
|
+
* @param {object} image The associated image.
|
|
226
|
+
* @returns {boolean} True if the tags are ok.
|
|
227
|
+
*/
|
|
228
|
+
export function mprCheckTags(tags, image) {
|
|
229
|
+
/**
|
|
230
|
+
* @param {number} value The value to check.
|
|
231
|
+
* @returns {number} The expected value.
|
|
232
|
+
*/
|
|
233
|
+
function getExpectedSize(value) {
|
|
234
|
+
return 2 * value;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
let needUpdate = false;
|
|
238
|
+
if (tags.Columns !== getExpectedSize(image.width)) {
|
|
239
|
+
tags.Columns = getExpectedSize(image.width);
|
|
240
|
+
needUpdate = true;
|
|
241
|
+
}
|
|
242
|
+
if (tags.Rows !== getExpectedSize(image.height)) {
|
|
243
|
+
tags.Rows = getExpectedSize(image.height);
|
|
244
|
+
needUpdate = true;
|
|
245
|
+
}
|
|
246
|
+
return needUpdate;
|
|
247
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>DICOM Anonymiser</title>
|
|
5
|
+
<meta charset="UTF-8">
|
|
6
|
+
<link rel="icon" href="../../favicon.ico"/>
|
|
7
|
+
<style>
|
|
8
|
+
body { font-family: Arial, Helvetica, sans-serif; }
|
|
9
|
+
textarea { width: 99%; margin: 2px; }
|
|
10
|
+
fieldset { background: whitesmoke; border: 1px solid grey; }
|
|
11
|
+
.button {
|
|
12
|
+
padding: 3px 7px 3px 7px;
|
|
13
|
+
text-align: center;
|
|
14
|
+
border-radius: 3px;
|
|
15
|
+
border: 1px solid grey;
|
|
16
|
+
text-decoration: none;
|
|
17
|
+
font: 80% sans-serif;
|
|
18
|
+
color: black;
|
|
19
|
+
background: #E3E3E3;
|
|
20
|
+
}
|
|
21
|
+
.button-active {
|
|
22
|
+
color: black;
|
|
23
|
+
background: #E3E3E3;
|
|
24
|
+
}
|
|
25
|
+
.button-disabled {
|
|
26
|
+
color: grey;
|
|
27
|
+
background: #F3F3F3;
|
|
28
|
+
}
|
|
29
|
+
.button:hover {
|
|
30
|
+
border: 1px solid black;
|
|
31
|
+
}
|
|
32
|
+
</style>
|
|
33
|
+
</head>
|
|
34
|
+
|
|
35
|
+
<body>
|
|
36
|
+
|
|
37
|
+
<h1>DWV DICOM Anonymiser</h1>
|
|
38
|
+
|
|
39
|
+
<p>Simple DICOM "anonymisation" tool. Available rules: <code>copy</code>,
|
|
40
|
+
<code>remove</code>, <code>clear</code>, <code>replace(value)</code>.</p>
|
|
41
|
+
|
|
42
|
+
<form name="genform">
|
|
43
|
+
|
|
44
|
+
<fieldset>
|
|
45
|
+
<label for="infile">DICOM file: </label>
|
|
46
|
+
<input id="infile" type="file" name="file">
|
|
47
|
+
<br>
|
|
48
|
+
<br><label for="inrulesfile">JSON rules file: </label>
|
|
49
|
+
<input id="inrulesfile" type="file" name="file">
|
|
50
|
+
</fieldset>
|
|
51
|
+
|
|
52
|
+
<textarea id="rules" rows="25">
|
|
53
|
+
{
|
|
54
|
+
"default": {
|
|
55
|
+
"action": "remove", "value": null
|
|
56
|
+
},
|
|
57
|
+
"PatientName": {
|
|
58
|
+
"action": "replace", "value": "Anonymised"
|
|
59
|
+
},
|
|
60
|
+
"Meta Element": {
|
|
61
|
+
"action": "copy", "value": null
|
|
62
|
+
},
|
|
63
|
+
"Acquisition": {
|
|
64
|
+
"action": "copy", "value": null
|
|
65
|
+
},
|
|
66
|
+
"Image Presentation": {
|
|
67
|
+
"action": "copy", "value": null
|
|
68
|
+
},
|
|
69
|
+
"Procedure": {
|
|
70
|
+
"action": "copy", "value": null
|
|
71
|
+
},
|
|
72
|
+
"Pixel Data": {
|
|
73
|
+
"action": "copy", "value": null
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
</textarea>
|
|
77
|
+
|
|
78
|
+
<fieldset>
|
|
79
|
+
<a href="#" id="jsonlint" class="button">JSONLint</a>
|
|
80
|
+
<a href="#" id="save" class="button">Save Rules</a>
|
|
81
|
+
<a href="#" id="generate" class="button button-disabled">Generate</a>
|
|
82
|
+
</fieldset>
|
|
83
|
+
</form>
|
|
84
|
+
|
|
85
|
+
</body>
|
|
86
|
+
</html>
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import {logger} from '../../../src/utils/logger.js';
|
|
2
|
+
import {DicomParser} from '../../../src/dicom/dicomParser.js';
|
|
3
|
+
import {DicomWriter} from '../../../src/dicom/dicomWriter.js';
|
|
4
|
+
|
|
5
|
+
// global vars
|
|
6
|
+
// rules file
|
|
7
|
+
let _rulesFile = null;
|
|
8
|
+
// dicom file
|
|
9
|
+
let _dicomFile = null;
|
|
10
|
+
// DICOM elements
|
|
11
|
+
let _dicomElements = null;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Setup.
|
|
15
|
+
*/
|
|
16
|
+
function setup() {
|
|
17
|
+
const infileInput = document.getElementById('infile');
|
|
18
|
+
infileInput.onchange = onInputDICOMFile;
|
|
19
|
+
const inrulesfileInput = document.getElementById('inrulesfile');
|
|
20
|
+
inrulesfileInput.onchange = onInputRulesFile;
|
|
21
|
+
const jsonlintButton = document.getElementById('jsonlint');
|
|
22
|
+
jsonlintButton.onclick = launchJSONLint;
|
|
23
|
+
const saveButton = document.getElementById('save');
|
|
24
|
+
saveButton.onclick = saveRules;
|
|
25
|
+
const generateButton = document.getElementById('generate');
|
|
26
|
+
generateButton.onclick = generate;
|
|
27
|
+
|
|
28
|
+
// logger level (optional)
|
|
29
|
+
logger.level = logger.levels.DEBUG;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Handle DICOM file load.
|
|
34
|
+
*
|
|
35
|
+
* @param {object} event The onload event.
|
|
36
|
+
*/
|
|
37
|
+
function onLoadDICOMFile(event) {
|
|
38
|
+
// parse DICOM
|
|
39
|
+
const parser = new DicomParser();
|
|
40
|
+
parser.parse(event.target.result);
|
|
41
|
+
// store elements
|
|
42
|
+
_dicomElements = parser.getDicomElements();
|
|
43
|
+
// activate generate button
|
|
44
|
+
const element = document.getElementById('generate');
|
|
45
|
+
element.className = 'button button-active';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Generate DICOM data.
|
|
50
|
+
*/
|
|
51
|
+
function generate() {
|
|
52
|
+
// check validity
|
|
53
|
+
if (!isValidRules()) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
// create writer with textarea rules
|
|
57
|
+
const writer = new DicomWriter();
|
|
58
|
+
const addMissingTags = true;
|
|
59
|
+
writer.setRules(
|
|
60
|
+
JSON.parse(document.getElementById('rules').value),
|
|
61
|
+
addMissingTags);
|
|
62
|
+
let dicomBuffer = null;
|
|
63
|
+
try {
|
|
64
|
+
dicomBuffer = writer.getBuffer(_dicomElements);
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.error(error);
|
|
67
|
+
alert(error.message);
|
|
68
|
+
}
|
|
69
|
+
// view as Blob to allow download
|
|
70
|
+
const blob = new Blob([dicomBuffer], {type: 'application/dicom'});
|
|
71
|
+
// update generate button
|
|
72
|
+
const element = document.getElementById('generate');
|
|
73
|
+
element.href = URL.createObjectURL(blob);
|
|
74
|
+
element.download = `anonym-${_dicomFile.name}`;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Save the rules as a JSON file.
|
|
79
|
+
*/
|
|
80
|
+
function saveRules() {
|
|
81
|
+
// check validity
|
|
82
|
+
if (!isValidRules()) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
// get text from the textarea
|
|
86
|
+
const text = document.getElementById('rules').value;
|
|
87
|
+
// view as Blob to allow download
|
|
88
|
+
const blob = new Blob([text], {type: 'text/plain'});
|
|
89
|
+
// update save button
|
|
90
|
+
const element = document.getElementById('save');
|
|
91
|
+
element.download = (_rulesFile === null ? 'rules.json' : _rulesFile.name);
|
|
92
|
+
element.href = URL.createObjectURL(blob);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Is the JSON valid?
|
|
97
|
+
*
|
|
98
|
+
* @returns {boolean} True if the input JSON is valid.
|
|
99
|
+
*/
|
|
100
|
+
function isValidRules() {
|
|
101
|
+
try {
|
|
102
|
+
JSON.parse(document.getElementById('rules').value);
|
|
103
|
+
} catch {
|
|
104
|
+
alert('The JSON is not valid, please check it with JSONLint.');
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Open JSONLint to check the rules.
|
|
112
|
+
*/
|
|
113
|
+
function launchJSONLint() {
|
|
114
|
+
const text = document.getElementById('rules').value;
|
|
115
|
+
const link = `http://jsonlint.com/?json=${encodeURIComponent(text)}`;
|
|
116
|
+
window.open(link);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Handle input DICOM file.
|
|
121
|
+
*
|
|
122
|
+
* @param {object} event The input field event.
|
|
123
|
+
*/
|
|
124
|
+
function onInputDICOMFile(event) {
|
|
125
|
+
if (event.target.files.length === 0) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
_dicomFile = event.target.files[0];
|
|
129
|
+
const reader = new FileReader();
|
|
130
|
+
reader.onload = onLoadDICOMFile;
|
|
131
|
+
reader.readAsArrayBuffer(_dicomFile);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Handle input rules file.
|
|
136
|
+
*
|
|
137
|
+
* @param {object} event The input field event.
|
|
138
|
+
*/
|
|
139
|
+
function onInputRulesFile(event) {
|
|
140
|
+
if (event.target.files.length === 0) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
_rulesFile = event.target.files[0];
|
|
144
|
+
const reader = new FileReader();
|
|
145
|
+
reader.onload = function (readerEvent) {
|
|
146
|
+
document.getElementById('rules').value = readerEvent.target.result;
|
|
147
|
+
};
|
|
148
|
+
reader.readAsText(_rulesFile);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// ---------------------------------------------
|
|
152
|
+
|
|
153
|
+
// launch
|
|
154
|
+
setup();
|