forked from cornerstonejs/cornerstone
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpixelDataToFalseColorData.js
More file actions
68 lines (62 loc) · 2.48 KB
/
Copy pathpixelDataToFalseColorData.js
File metadata and controls
68 lines (62 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import colors from './colors/index.js';
/**
* Converts the image pixel data into a false color data
*
* @param {Image} image A Cornerstone Image Object
* @param {Object} lookupTable A lookup table Object
*
* @returns {void}
*/
export default function (image, lookupTable) {
if (image.color && !image.falseColor) {
throw new Error('Color transforms are not implemented yet');
}
const minPixelValue = image.minPixelValue;
let canvasImageDataIndex = 0;
let storedPixelDataIndex = 0;
const numPixels = image.width * image.height;
const origPixelData = image.origPixelData || image.getPixelData();
const storedColorPixelData = new Uint8Array(numPixels * 4);
let sp;
let mapped;
image.color = true;
image.falseColor = true;
image.origPixelData = origPixelData;
if (lookupTable instanceof colors.LookupTable) {
lookupTable.build();
while (storedPixelDataIndex < numPixels) {
sp = origPixelData[storedPixelDataIndex++];
mapped = lookupTable.mapValue(sp);
storedColorPixelData[canvasImageDataIndex++] = mapped[0];
storedColorPixelData[canvasImageDataIndex++] = mapped[1];
storedColorPixelData[canvasImageDataIndex++] = mapped[2];
storedColorPixelData[canvasImageDataIndex++] = mapped[3];
}
} else if (minPixelValue < 0) {
while (storedPixelDataIndex < numPixels) {
sp = origPixelData[storedPixelDataIndex++];
storedColorPixelData[canvasImageDataIndex++] = lookupTable[sp + (-minPixelValue)][0]; // Red
storedColorPixelData[canvasImageDataIndex++] = lookupTable[sp + (-minPixelValue)][1]; // Green
storedColorPixelData[canvasImageDataIndex++] = lookupTable[sp + (-minPixelValue)][2]; // Blue
storedColorPixelData[canvasImageDataIndex++] = lookupTable[sp + (-minPixelValue)][3]; // Alpha
}
} else {
while (storedPixelDataIndex < numPixels) {
sp = origPixelData[storedPixelDataIndex++];
storedColorPixelData[canvasImageDataIndex++] = lookupTable[sp][0]; // Red
storedColorPixelData[canvasImageDataIndex++] = lookupTable[sp][1]; // Green
storedColorPixelData[canvasImageDataIndex++] = lookupTable[sp][2]; // Blue
storedColorPixelData[canvasImageDataIndex++] = lookupTable[sp][3]; // Alpha
}
}
image.rgba = true;
image.cachedLut = undefined;
image.render = undefined;
image.slope = 1;
image.intercept = 0;
image.minPixelValue = 0;
image.maxPixelValue = 255;
image.windowWidth = 255;
image.windowCenter = 128;
image.getPixelData = () => storedColorPixelData;
}