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
package/dev/bench/gui.js
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
// namespace
|
|
2
|
+
// eslint-disable-next-line no-var
|
|
3
|
+
var dcmb = dcmb || {};
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Get an html span with input text.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} text The span text.
|
|
9
|
+
* @returns {object} A DOM span.
|
|
10
|
+
*/
|
|
11
|
+
dcmb.getDomSpan = function (text) {
|
|
12
|
+
const span = document.createElement('span');
|
|
13
|
+
span.appendChild(document.createTextNode(text));
|
|
14
|
+
return span;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Get an html span with the difference of the two input values as a percentage.
|
|
19
|
+
*
|
|
20
|
+
* @param {number} base The base number.
|
|
21
|
+
* @param {number} current The number to compare to the base.
|
|
22
|
+
* @returns {object} A DOM span inculding the percentage text.
|
|
23
|
+
*/
|
|
24
|
+
dcmb.getDiffSpan = function (base, current) {
|
|
25
|
+
const diff = current - base;
|
|
26
|
+
const sign = diff >= 0 ? '+' : '';
|
|
27
|
+
const percent = diff * 100 / base;
|
|
28
|
+
const percentTxt = percent.toFixed(percent < 100 ? 2 : 0);
|
|
29
|
+
|
|
30
|
+
const span = dcmb.getDomSpan(`(${sign}${percentTxt}%)`);
|
|
31
|
+
span.className = 'stats';
|
|
32
|
+
span.className += diff >= 0 ? ' positive' : ' negative';
|
|
33
|
+
return span;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Get an html span with input Root Mean Error (RME).
|
|
38
|
+
*
|
|
39
|
+
* @param {number} rme The RME.
|
|
40
|
+
* @returns {object} A DOM span inculding the rme text.
|
|
41
|
+
*/
|
|
42
|
+
dcmb.getRmeSpan = function (rme) {
|
|
43
|
+
const rmeTxt = rme.toFixed(rme < 100 ? 2 : 0);
|
|
44
|
+
const span = dcmb.getDomSpan(`\u00B1${rmeTxt}%`);
|
|
45
|
+
span.className = 'stats';
|
|
46
|
+
span.className += Math.abs(rme) >= 10 ? ' red' : ' green';
|
|
47
|
+
return span;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Get the mean values of each columns of the input array.
|
|
52
|
+
*
|
|
53
|
+
* @param {Array} results The value array of arrays.
|
|
54
|
+
* @returns {Array} A vector with each columns mean.
|
|
55
|
+
*/
|
|
56
|
+
dcmb.getMeans = function (results) {
|
|
57
|
+
const nrows = results.length;
|
|
58
|
+
const ncols = results[0].length;
|
|
59
|
+
// check number of cols
|
|
60
|
+
for (let i = 0; i < nrows; ++i) {
|
|
61
|
+
if (results[i].length !== ncols) {
|
|
62
|
+
throw new Error('Different number of columns...');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// sum along columns
|
|
66
|
+
const means = [];
|
|
67
|
+
for (let j = 0; j < ncols; ++j) {
|
|
68
|
+
let sum = 0;
|
|
69
|
+
for (let k = 0; k < nrows; ++k) {
|
|
70
|
+
sum += dcmb.parseData(results[k][j]).value;
|
|
71
|
+
}
|
|
72
|
+
means.push(sum / nrows);
|
|
73
|
+
}
|
|
74
|
+
return means;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Parse result data: if string anything before space is the value.
|
|
79
|
+
*
|
|
80
|
+
* @param {Array} data The data to parse.
|
|
81
|
+
* @returns {object} The data split in {value, extra}.
|
|
82
|
+
*/
|
|
83
|
+
dcmb.parseData = function (data) {
|
|
84
|
+
let value = data;
|
|
85
|
+
let extra = '';
|
|
86
|
+
if (typeof data === 'string') {
|
|
87
|
+
const split = data.split(' ');
|
|
88
|
+
value = parseFloat(split.splice(0, 1));
|
|
89
|
+
extra = ` ${split.join(' ')}`;
|
|
90
|
+
}
|
|
91
|
+
return {value, extra};
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* To fixed for display.
|
|
96
|
+
*
|
|
97
|
+
* @param {number} value The nunmber to format.
|
|
98
|
+
* @returns {number} The formated number.
|
|
99
|
+
*/
|
|
100
|
+
dcmb.toFixed = function (value) {
|
|
101
|
+
return value.toFixed(value < 100 ? 2 : 0);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Create a HTML table from result data.
|
|
106
|
+
*
|
|
107
|
+
* @param {Array} colHeader The column header data.
|
|
108
|
+
* @param {Array} dataHeader The data header, ie row header data.
|
|
109
|
+
* @param {Array} bodyData The result 'raw' data.
|
|
110
|
+
* @param {Array} footData Some foot data.
|
|
111
|
+
*/
|
|
112
|
+
|
|
113
|
+
dcmb.createTable = function (colHeader, dataHeader, bodyData, footData) {
|
|
114
|
+
let row;
|
|
115
|
+
let cell;
|
|
116
|
+
|
|
117
|
+
const table = document.createElement('table');
|
|
118
|
+
|
|
119
|
+
// head
|
|
120
|
+
const tableHead = document.createElement('thead');
|
|
121
|
+
row = document.createElement('tr');
|
|
122
|
+
// empty first cell
|
|
123
|
+
cell = document.createElement('td');
|
|
124
|
+
cell.appendChild(document.createTextNode(''));
|
|
125
|
+
row.appendChild(cell);
|
|
126
|
+
tableHead.appendChild(row);
|
|
127
|
+
// column headers
|
|
128
|
+
for (let k = 0; k < colHeader.length; ++k) {
|
|
129
|
+
cell = document.createElement('td');
|
|
130
|
+
cell.appendChild(document.createTextNode(colHeader[k]));
|
|
131
|
+
row.appendChild(cell);
|
|
132
|
+
tableHead.appendChild(row);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// body
|
|
136
|
+
const tableBody = document.createElement('tbody');
|
|
137
|
+
for (let i = 0; i < bodyData.length; ++i) {
|
|
138
|
+
row = document.createElement('tr');
|
|
139
|
+
// data header
|
|
140
|
+
cell = document.createElement('td');
|
|
141
|
+
cell.appendChild(document.createTextNode(dataHeader[i]));
|
|
142
|
+
row.appendChild(cell);
|
|
143
|
+
tableBody.appendChild(row);
|
|
144
|
+
// body data
|
|
145
|
+
const rowData = bodyData[i];
|
|
146
|
+
for (let j = 0; j < rowData.length; ++j) {
|
|
147
|
+
cell = document.createElement('td');
|
|
148
|
+
const pData = dcmb.parseData(rowData[j]);
|
|
149
|
+
cell.appendChild(document.createTextNode(dcmb.toFixed(pData.value)));
|
|
150
|
+
cell.appendChild(document.createTextNode(pData.extra));
|
|
151
|
+
if (j > 0) {
|
|
152
|
+
cell.appendChild(document.createTextNode(' '));
|
|
153
|
+
const v0 = dcmb.parseData(rowData[0]).value;
|
|
154
|
+
cell.appendChild(dcmb.getDiffSpan(v0, pData.value));
|
|
155
|
+
}
|
|
156
|
+
row.appendChild(cell);
|
|
157
|
+
}
|
|
158
|
+
tableBody.appendChild(row);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// head
|
|
162
|
+
const tableFoot = document.createElement('tfoot');
|
|
163
|
+
row = document.createElement('tr');
|
|
164
|
+
// column headers
|
|
165
|
+
for (let l = 0; l < footData.length; ++l) {
|
|
166
|
+
cell = document.createElement('td');
|
|
167
|
+
let value = footData[l];
|
|
168
|
+
if (l !== 0) {
|
|
169
|
+
value = dcmb.toFixed(value);
|
|
170
|
+
}
|
|
171
|
+
cell.appendChild(document.createTextNode(value));
|
|
172
|
+
if (l > 1) {
|
|
173
|
+
cell.appendChild(document.createTextNode(' '));
|
|
174
|
+
cell.appendChild(dcmb.getDiffSpan(footData[1], footData[l]));
|
|
175
|
+
}
|
|
176
|
+
row.appendChild(cell);
|
|
177
|
+
tableFoot.appendChild(row);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
table.appendChild(tableHead);
|
|
181
|
+
table.appendChild(tableBody);
|
|
182
|
+
table.appendChild(tableFoot);
|
|
183
|
+
return table;
|
|
184
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// namespaces
|
|
2
|
+
// eslint-disable-next-line no-var
|
|
3
|
+
var dcmb = dcmb || {};
|
|
4
|
+
dcmb.utils = dcmb.utils || {};
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* ListenerHandler class: handles add/removing and firing listeners.
|
|
8
|
+
*
|
|
9
|
+
* @class
|
|
10
|
+
*/
|
|
11
|
+
dcmb.utils.ListenerHandler = function () {
|
|
12
|
+
/**
|
|
13
|
+
* Listeners.
|
|
14
|
+
*
|
|
15
|
+
* @private
|
|
16
|
+
*/
|
|
17
|
+
const listeners = {};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Add an event listener.
|
|
21
|
+
*
|
|
22
|
+
* @param {string} type The event type.
|
|
23
|
+
* @param {object} callback The method associated with the provided
|
|
24
|
+
* event type, will be called with the fired event.
|
|
25
|
+
*/
|
|
26
|
+
this.add = function (type, callback) {
|
|
27
|
+
// create array if not present
|
|
28
|
+
if (typeof listeners[type] === 'undefined') {
|
|
29
|
+
listeners[type] = [];
|
|
30
|
+
}
|
|
31
|
+
// add callback to listeners array
|
|
32
|
+
listeners[type].push(callback);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Remove an event listener.
|
|
37
|
+
*
|
|
38
|
+
* @param {string} type The event type.
|
|
39
|
+
* @param {object} callback The method associated with the provided
|
|
40
|
+
* event type.
|
|
41
|
+
*/
|
|
42
|
+
this.remove = function (type, callback) {
|
|
43
|
+
// check if the type is present
|
|
44
|
+
if (typeof listeners[type] === 'undefined') {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
// remove from listeners array
|
|
48
|
+
for (let i = 0; i < listeners[type].length; ++i) {
|
|
49
|
+
if (listeners[type][i] === callback) {
|
|
50
|
+
listeners[type].splice(i, 1);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Fire an event: call all associated listeners with the input event object.
|
|
57
|
+
*
|
|
58
|
+
* @param {object} event The event to fire.
|
|
59
|
+
*/
|
|
60
|
+
this.fireEvent = function (event) {
|
|
61
|
+
// check if they are listeners for the event type
|
|
62
|
+
if (typeof listeners[event.type] === 'undefined') {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
// fire events
|
|
66
|
+
for (let i = 0; i < listeners[event.type].length; ++i) {
|
|
67
|
+
listeners[event.type][i](event);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<title>iframe-dwv</title>
|
|
6
|
+
<meta charset="UTF-8">
|
|
7
|
+
</head>
|
|
8
|
+
|
|
9
|
+
<script src="../../../dist/dwv.min.js"></script>
|
|
10
|
+
|
|
11
|
+
<script type="text/javascript">
|
|
12
|
+
tests = [
|
|
13
|
+
{
|
|
14
|
+
setup: function (buffer) {
|
|
15
|
+
return buffer;
|
|
16
|
+
},
|
|
17
|
+
run: function (buffer) {
|
|
18
|
+
// parse the dicom buffer
|
|
19
|
+
var dwvParser = new dwv.DicomParser();
|
|
20
|
+
dwvParser.parse(buffer);
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
setup: function (buffer) {
|
|
25
|
+
// parse the dicom buffer
|
|
26
|
+
var dwvParser = new dwv.DicomParser();
|
|
27
|
+
dwvParser.parse(buffer);
|
|
28
|
+
// return
|
|
29
|
+
return [dwvParser.getDicomElements()];
|
|
30
|
+
},
|
|
31
|
+
run: function (input) {
|
|
32
|
+
const elements = input[0];
|
|
33
|
+
// create the image
|
|
34
|
+
const image = dwv.createImage(elements);
|
|
35
|
+
// create the view
|
|
36
|
+
const view = dwv.createView(elements, image);
|
|
37
|
+
// generate image data
|
|
38
|
+
var imgData = new ImageData(256, 256);
|
|
39
|
+
view.generateImageData(imgData);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
];
|
|
43
|
+
</script>
|
|
44
|
+
|
|
45
|
+
</html>
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<title>iframe-dwv</title>
|
|
6
|
+
<meta charset="UTF-8">
|
|
7
|
+
</head>
|
|
8
|
+
|
|
9
|
+
<script src="https://unpkg.com/dwv"></script>
|
|
10
|
+
|
|
11
|
+
<script type="text/javascript">
|
|
12
|
+
tests = [
|
|
13
|
+
{
|
|
14
|
+
setup: function (buffer) {
|
|
15
|
+
return buffer;
|
|
16
|
+
},
|
|
17
|
+
run: function (buffer) {
|
|
18
|
+
// parse the dicom buffer
|
|
19
|
+
var dwvParser = new dwv.DicomParser();
|
|
20
|
+
dwvParser.parse(buffer);
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
setup: function (buffer) {
|
|
25
|
+
// parse the dicom buffer
|
|
26
|
+
var dwvParser = new dwv.DicomParser();
|
|
27
|
+
dwvParser.parse(buffer);
|
|
28
|
+
// return
|
|
29
|
+
return [dwvParser.getDicomElements()];
|
|
30
|
+
},
|
|
31
|
+
run: function (input) {
|
|
32
|
+
const elements = input[0];
|
|
33
|
+
// create the image
|
|
34
|
+
const image = dwv.createImage(elements);
|
|
35
|
+
// create the view
|
|
36
|
+
const view = dwv.createView(elements, image);
|
|
37
|
+
// generate image data
|
|
38
|
+
var imgData = new ImageData(256, 256);
|
|
39
|
+
view.generateImageData(imgData);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
];
|
|
43
|
+
</script>
|
|
44
|
+
|
|
45
|
+
</html>
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BinaryPixGenerator: generates binary pixel data.
|
|
3
|
+
*/
|
|
4
|
+
export class BinaryPixGenerator {
|
|
5
|
+
|
|
6
|
+
#numberOfColumns;
|
|
7
|
+
#numberOfRows;
|
|
8
|
+
#numberOfFrames;
|
|
9
|
+
#shape = 'square';
|
|
10
|
+
|
|
11
|
+
#squares;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {object} options The generator options.
|
|
15
|
+
*/
|
|
16
|
+
constructor(options) {
|
|
17
|
+
this.#numberOfColumns = options.numberOfColumns;
|
|
18
|
+
this.#numberOfRows = options.numberOfRows;
|
|
19
|
+
this.#numberOfFrames = options.numberOfFrames;
|
|
20
|
+
|
|
21
|
+
if (typeof options.shape !== 'undefined') {
|
|
22
|
+
this.#shape = options.shape;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (typeof options.segmentSquares !== 'undefined') {
|
|
26
|
+
this.#squares = options.segmentSquares;
|
|
27
|
+
} else {
|
|
28
|
+
// default square
|
|
29
|
+
const borderI = Math.ceil(this.#numberOfColumns * 0.25);
|
|
30
|
+
const borderJ = Math.ceil(this.#numberOfRows * 0.25);
|
|
31
|
+
this.#squares = {};
|
|
32
|
+
for (let f = 0; f < this.#numberOfFrames; ++f) {
|
|
33
|
+
this.#squares[String(f + 1)] = {
|
|
34
|
+
minI: borderI,
|
|
35
|
+
maxI: this.#numberOfColumns - borderI,
|
|
36
|
+
minJ: borderJ,
|
|
37
|
+
maxJ: this.#numberOfRows - borderJ
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @param {number[]} pixelBuffer The buffer.
|
|
46
|
+
*/
|
|
47
|
+
generate(pixelBuffer /*, sliceNumber*/) {
|
|
48
|
+
let offset = 0;
|
|
49
|
+
for (let f = 0; f < this.#numberOfFrames; ++f) {
|
|
50
|
+
for (let j = 0; j < this.#numberOfRows; ++j) {
|
|
51
|
+
for (let i = 0; i < this.#numberOfColumns; ++i) {
|
|
52
|
+
pixelBuffer[offset] = this.#getValue(i, j, f);
|
|
53
|
+
++offset;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @param {number} i The column index.
|
|
61
|
+
* @param {number} j The row index.
|
|
62
|
+
* @param {number} f The frame index.
|
|
63
|
+
* @returns {number} The value.
|
|
64
|
+
*/
|
|
65
|
+
#getValue = (i, j, f) => {
|
|
66
|
+
let res = 0;
|
|
67
|
+
if (this.#shape === 'square') {
|
|
68
|
+
res = this.#getValueSquare(i, j, f);
|
|
69
|
+
} else if (this.#shape === 'diamond') {
|
|
70
|
+
res = this.#getValueDiamond(i, j, f);
|
|
71
|
+
}
|
|
72
|
+
return res;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @param {number} i The column index.
|
|
77
|
+
* @param {number} j The row index.
|
|
78
|
+
* @param {number} f The frame index.
|
|
79
|
+
* @returns {number} The value.
|
|
80
|
+
*/
|
|
81
|
+
#getValueSquare = (i, j, f) => {
|
|
82
|
+
const sq = this.#squares[String(f + 1)];
|
|
83
|
+
const inRange = i >= sq.minI && i < sq.maxI &&
|
|
84
|
+
j >= sq.minJ && j < sq.maxJ;
|
|
85
|
+
return inRange ? 1 : 0;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @param {number} i The column index.
|
|
90
|
+
* @param {number} j The row index.
|
|
91
|
+
* @param {number} f The frame index.
|
|
92
|
+
* @returns {number} The value.
|
|
93
|
+
*/
|
|
94
|
+
#getValueDiamond = (i, j, f) => {
|
|
95
|
+
let res = 0;
|
|
96
|
+
|
|
97
|
+
const sq = this.#squares[String(f + 1)];
|
|
98
|
+
const middleI = sq.minI + Math.floor((sq.maxI - sq.minI) * 0.5);
|
|
99
|
+
const middleJ = sq.minJ + Math.floor((sq.maxJ - sq.minJ) * 0.5);
|
|
100
|
+
|
|
101
|
+
const n = j < middleJ ? j - sq.minJ : sq.maxJ - j;
|
|
102
|
+
if (Math.abs(i - middleI) < n) {
|
|
103
|
+
res = 1;
|
|
104
|
+
}
|
|
105
|
+
return res;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
};
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
|
|
2
|
+
import {getTypedArray} from '../../src/dicom/dicomParser.js';
|
|
3
|
+
import {getPixelDataTag} from '../../src/dicom/dicomTag.js';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
BinaryPixGenerator
|
|
7
|
+
} from './binaryPixGenerator.js';
|
|
8
|
+
import {
|
|
9
|
+
FilePixGenerator,
|
|
10
|
+
fileCheckTags
|
|
11
|
+
} from './filePixGenerator.js';
|
|
12
|
+
import {
|
|
13
|
+
GradSquarePixGenerator
|
|
14
|
+
} from './gradSquarePixGenerator.js';
|
|
15
|
+
import {
|
|
16
|
+
MPRPixGenerator,
|
|
17
|
+
mprCheckTags
|
|
18
|
+
} from './mprPixGenerator.js';
|
|
19
|
+
import {
|
|
20
|
+
SquarePixGenerator
|
|
21
|
+
} from './squarePixGenerator.js';
|
|
22
|
+
|
|
23
|
+
// List of pixel generators
|
|
24
|
+
export const _pixelGenerators = {
|
|
25
|
+
binary: {generator: BinaryPixGenerator},
|
|
26
|
+
file: {generator: FilePixGenerator, checkTags: fileCheckTags},
|
|
27
|
+
gradSquare: {generator: GradSquarePixGenerator},
|
|
28
|
+
mpr: {generator: MPRPixGenerator, checkTags: mprCheckTags},
|
|
29
|
+
square: {generator: SquarePixGenerator}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// List of required tags for generating pixel data
|
|
33
|
+
const _requiredPixelTags = [
|
|
34
|
+
'TransferSyntaxUID',
|
|
35
|
+
'Rows',
|
|
36
|
+
'Columns',
|
|
37
|
+
'BitsAllocated',
|
|
38
|
+
'PixelRepresentation',
|
|
39
|
+
'SamplesPerPixel',
|
|
40
|
+
'PhotometricInterpretation'
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Check a list of input tags against a required list.
|
|
45
|
+
*
|
|
46
|
+
* @param {object} tags The tags to check.
|
|
47
|
+
* @param {Array} requiredTags Array of tag names.
|
|
48
|
+
* @param {boolean} withLog Flag to log errors or not.
|
|
49
|
+
* @returns {boolean} True if all required tags are present in the input.
|
|
50
|
+
*/
|
|
51
|
+
export function checkTags(tags, requiredTags, withLog) {
|
|
52
|
+
if (typeof withLog === 'undefined') {
|
|
53
|
+
withLog = false;
|
|
54
|
+
}
|
|
55
|
+
let check = true;
|
|
56
|
+
for (let i = 0; i < requiredTags.length; ++i) {
|
|
57
|
+
if (typeof tags[requiredTags[i]] === 'undefined') {
|
|
58
|
+
if (withLog) {
|
|
59
|
+
console.log(`Missing ${
|
|
60
|
+
requiredTags[i] } for pixel generation.`);
|
|
61
|
+
}
|
|
62
|
+
check = false;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return check;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Get the DICOM pixel data from a DICOM tags object.
|
|
71
|
+
*
|
|
72
|
+
* @param {object} tags The DICOM tags object.
|
|
73
|
+
* @param {object} [options] The options for pixel generation.
|
|
74
|
+
* @param {string} [options.pixelGeneratorName] The name of the pixel generator
|
|
75
|
+
* to use, defaults to gradSquare.
|
|
76
|
+
* @param {number} [options.sliceNumber] The slice number,
|
|
77
|
+
* default to 0.
|
|
78
|
+
* @param {Array} [options.images] The images to pass to the generator.
|
|
79
|
+
* @param {number} [options.numberOfSlices] The result number of slices,
|
|
80
|
+
* default to 1.
|
|
81
|
+
* @returns {object} The DICOM pixel data element.
|
|
82
|
+
*/
|
|
83
|
+
export function generatePixelDataFromJSONTags(
|
|
84
|
+
tags, options) {
|
|
85
|
+
if (typeof options === 'undefined') {
|
|
86
|
+
options = {};
|
|
87
|
+
}
|
|
88
|
+
// default
|
|
89
|
+
if (typeof options.pixelGeneratorName === 'undefined') {
|
|
90
|
+
options.pixelGeneratorName = 'gradSquare';
|
|
91
|
+
}
|
|
92
|
+
if (typeof options.sliceNumber === 'undefined') {
|
|
93
|
+
options.sliceNumber = 0;
|
|
94
|
+
}
|
|
95
|
+
if (typeof options.numberOfSlices === 'undefined') {
|
|
96
|
+
options.numberOfSlices = 1;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// check tags
|
|
100
|
+
if (!checkTags(tags, _requiredPixelTags, true)) {
|
|
101
|
+
throw new Error('Missing meta data for dicom creation.');
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// extract info from tags
|
|
105
|
+
const numberOfRows = tags.Rows;
|
|
106
|
+
const numberOfColumns = tags.Columns;
|
|
107
|
+
let numberOfFrames = 1;
|
|
108
|
+
if (typeof tags.NumberOfFrames !== 'undefined') {
|
|
109
|
+
numberOfFrames = tags.NumberOfFrames;
|
|
110
|
+
}
|
|
111
|
+
const bitsAllocated = tags.BitsAllocated;
|
|
112
|
+
const pixelRepresentation = tags.PixelRepresentation;
|
|
113
|
+
const samplesPerPixel = tags.SamplesPerPixel;
|
|
114
|
+
// trim in case config contains padding
|
|
115
|
+
const photometricInterpretation = tags.PhotometricInterpretation.trim();
|
|
116
|
+
|
|
117
|
+
const sliceLength = numberOfRows * numberOfColumns;
|
|
118
|
+
const dataLength = sliceLength * numberOfFrames * samplesPerPixel;
|
|
119
|
+
|
|
120
|
+
// check values
|
|
121
|
+
if (samplesPerPixel !== 1 && samplesPerPixel !== 3) {
|
|
122
|
+
throw new Error(
|
|
123
|
+
`Unsupported SamplesPerPixel for pixel generation: ${
|
|
124
|
+
samplesPerPixel }`);
|
|
125
|
+
}
|
|
126
|
+
if ((samplesPerPixel === 1 && !(photometricInterpretation === 'MONOCHROME1' ||
|
|
127
|
+
photometricInterpretation === 'MONOCHROME2')) ||
|
|
128
|
+
(samplesPerPixel === 3 && photometricInterpretation !== 'RGB')) {
|
|
129
|
+
throw new Error(
|
|
130
|
+
`Unsupported PhotometricInterpretation for pixel generation: ${
|
|
131
|
+
photometricInterpretation } with SamplesPerPixel: ${samplesPerPixel}`);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
let numberOfSamples = 1;
|
|
135
|
+
let numberOfColourPlanes = 1;
|
|
136
|
+
if (samplesPerPixel === 3) {
|
|
137
|
+
if (typeof tags.PlanarConfiguration === 'undefined') {
|
|
138
|
+
throw new Error('Missing PlanarConfiguration for pixel generation.');
|
|
139
|
+
}
|
|
140
|
+
const planarConfiguration = tags.PlanarConfiguration;
|
|
141
|
+
if (planarConfiguration !== 0 && planarConfiguration !== 1) {
|
|
142
|
+
throw new Error(
|
|
143
|
+
`Unsupported PlanarConfiguration for pixel generation: ${
|
|
144
|
+
planarConfiguration }`);
|
|
145
|
+
}
|
|
146
|
+
if (planarConfiguration === 0) {
|
|
147
|
+
numberOfSamples = 3;
|
|
148
|
+
} else {
|
|
149
|
+
numberOfColourPlanes = 3;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// create pixel array
|
|
154
|
+
const pixels = getTypedArray(
|
|
155
|
+
bitsAllocated, pixelRepresentation, dataLength);
|
|
156
|
+
|
|
157
|
+
// pixels generator
|
|
158
|
+
if (typeof _pixelGenerators[options.pixelGeneratorName] === 'undefined') {
|
|
159
|
+
throw new Error(
|
|
160
|
+
`Unknown PixelData generator: ${options.pixelGeneratorName}`
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
const GeneratorClass = _pixelGenerators[options.pixelGeneratorName].generator;
|
|
164
|
+
const generator = new GeneratorClass({
|
|
165
|
+
numberOfColumns,
|
|
166
|
+
numberOfRows,
|
|
167
|
+
numberOfSlices: options.numberOfSlices,
|
|
168
|
+
numberOfFrames,
|
|
169
|
+
numberOfSamples,
|
|
170
|
+
numberOfColourPlanes,
|
|
171
|
+
photometricInterpretation,
|
|
172
|
+
imageOrientationPatient: tags.ImageOrientationPatient,
|
|
173
|
+
segmentSquares: options.segmentSquares
|
|
174
|
+
});
|
|
175
|
+
if (typeof generator.setImages !== 'undefined' &&
|
|
176
|
+
typeof options.images !== 'undefined') {
|
|
177
|
+
generator.setImages(options.images);
|
|
178
|
+
}
|
|
179
|
+
if (typeof generator.setNumberOfSlices !== 'undefined') {
|
|
180
|
+
generator.setNumberOfSlices(options.numberOfSlices);
|
|
181
|
+
}
|
|
182
|
+
generator.generate(pixels, options.sliceNumber);
|
|
183
|
+
|
|
184
|
+
// create and return the DICOM element
|
|
185
|
+
let vr = 'OW';
|
|
186
|
+
if (bitsAllocated === 8) {
|
|
187
|
+
vr = 'OB';
|
|
188
|
+
}
|
|
189
|
+
const pixVL = pixels.BYTES_PER_ELEMENT * dataLength;
|
|
190
|
+
return {
|
|
191
|
+
tag: getPixelDataTag(),
|
|
192
|
+
vr,
|
|
193
|
+
vl: pixVL,
|
|
194
|
+
value: pixels
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Extract the image data from an image.
|
|
200
|
+
*
|
|
201
|
+
* @param {Image} image The image to get the data from.
|
|
202
|
+
* @returns {object} The image data buffer.
|
|
203
|
+
*/
|
|
204
|
+
export function getImageDataData(image) {
|
|
205
|
+
// draw the image in the canvas in order to get its data
|
|
206
|
+
const canvas = document.createElement('canvas');
|
|
207
|
+
canvas.width = image.width;
|
|
208
|
+
canvas.height = image.height;
|
|
209
|
+
const ctx = canvas.getContext('2d');
|
|
210
|
+
ctx.drawImage(image, 0, 0);
|
|
211
|
+
// get the image data
|
|
212
|
+
const imageData = ctx.getImageData(0, 0, image.width, image.height);
|
|
213
|
+
// data.data
|
|
214
|
+
return imageData.data;
|
|
215
|
+
};
|