dwv 0.37.0-beta.8 → 0.37.0
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/dist/assets/workers/jpeg2000.worker.min.js +1 -1
- package/dist/assets/workers/jpeg2000.worker.min.js.map +1 -1
- package/dist/assets/workers/jpegbaseline.worker.min.js +1 -1
- package/dist/assets/workers/jpegbaseline.worker.min.js.map +1 -1
- package/dist/assets/workers/jpegloss.worker.min.js +1 -1
- package/dist/assets/workers/jpegloss.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/assets/workers/rle.worker.min.js +1 -1
- package/dist/assets/workers/rle.worker.min.js.map +1 -1
- package/dist/dwv.d.ts +1333 -314
- 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 +21 -23
- package/readme.md +7 -3
- package/dev/bench/bench.html +0 -94
- package/dev/bench/bench.js +0 -316
- package/dev/bench/benchFunctionRunner.js +0 -83
- package/dev/bench/dataRunner.js +0 -171
- package/dev/bench/gui.js +0 -184
- package/dev/bench/listen.js +0 -70
- package/dev/bench/parsers/dwv-current.html +0 -45
- package/dev/bench/parsers/dwv-previous.html +0 -45
- package/dev/dicom/binaryPixGenerator.js +0 -108
- package/dev/dicom/dicomGenerator.js +0 -215
- package/dev/dicom/filePixGenerator.js +0 -96
- package/dev/dicom/gradSquarePixGenerator.js +0 -107
- package/dev/dicom/mprPixGenerator.js +0 -247
- package/dev/dicom/pages/anonymiser.html +0 -86
- package/dev/dicom/pages/anonymiser.js +0 -154
- package/dev/dicom/pages/diff.html +0 -34
- package/dev/dicom/pages/diff.js +0 -97
- package/dev/dicom/pages/generator.html +0 -92
- package/dev/dicom/pages/generator.js +0 -329
- package/dev/dicom/pages/synthetic-data.html +0 -19
- package/dev/dicom/pages/synthetic-data.js +0 -164
- package/dev/dicom/squarePixGenerator.js +0 -233
- package/dev/favicon.ico +0 -0
- package/dev/image/pages/colourmaps.html +0 -16
- package/dev/image/pages/colourmaps.js +0 -65
- package/dev/index.html +0 -38
- package/dev/pacs/dcmweb.html +0 -80
- package/dev/pacs/dcmweb.js +0 -577
- 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 +0 -97
- package/dev/pacs/index.js +0 -287
- package/dev/pacs/overlays.js +0 -51
- package/dev/pacs/viewer.html +0 -401
- package/dev/pacs/viewer.js +0 -1275
- package/dev/pacs/viewer.rendertest.js +0 -96
- package/dev/pacs/viewer.ui.annot.js +0 -607
- package/dev/pacs/viewer.ui.brush.js +0 -181
- package/dev/pacs/viewer.ui.datatable.js +0 -674
- package/dev/pacs/viewer.ui.draw.js +0 -141
- package/dev/pacs/viewer.ui.icons.js +0 -88
- package/dev/pacs/viewer.ui.js +0 -198
- package/dev/pacs/viewer.ui.segment.js +0 -1369
- package/dev/visual/appgui.js +0 -125
- 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 +0 -104
- package/dev/visual/index-jpeg2000.js +0 -103
- package/dev/visual/index-rle.js +0 -70
- package/dev/visual/index.html +0 -20
- package/dev/visual/index.js +0 -123
- package/dev/visual/style.css +0 -37
|
@@ -1,215 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,96 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,247 +0,0 @@
|
|
|
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
|
-
}
|