Skip to content

Commit 2cac920

Browse files
pierreldffpleduff
andauthored
fix: Correct float access to lut array (#302) (#303)
* Correct float access to lut array (#302) * Fix performance issue (#302) Co-authored-by: pleduff <[email protected]>
1 parent 7acd99a commit 2cac920

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/internal/generateLut.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ export default function (image, windowWidth, windowCenter, invert, modalityLUT,
2828
}
2929

3030
const lut = image.cachedLut.lutArray;
31+
var slopeOrInterceptAreFloat = !!(image.slope % 1) || !!(image.intercept % 1);
3132
const mlutfn = getModalityLUT(image.slope, image.intercept, modalityLUT);
32-
const vlutfn = getVOILUT(windowWidth, windowCenter, voiLUT);
33+
const vlutfn = getVOILUT(windowWidth, windowCenter, voiLUT, slopeOrInterceptAreFloat);
3334

3435
if (invert === true) {
3536
for (let storedValue = minPixelValue; storedValue <= maxPixelValue; storedValue++) {

src/internal/getVOILut.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ function generateLinearVOILUT (windowWidth, windowCenter) {
3030
/**
3131
* Generate a non-linear volume of interest lookup table
3232
*
33-
* @param {LUT} voiLUT Volume of Interest Lookup Table Object
33+
* @param {LUT} voiLUT Volume of Interest Lookup Table Object
34+
* @param {Boolean} roundModalityLUTValues Do a Math.round of modality lut to compute non linear voilut
35+
3436
*
3537
* @returns {VOILUTFunction} VOI LUT mapping function
3638
* @memberof VOILUT
3739
*/
38-
function generateNonLinearVOILUT (voiLUT) {
40+
function generateNonLinearVOILUT (voiLUT, roundModalityLUTValues) {
3941
// We don't trust the voiLUT.numBitsPerEntry, mainly thanks to Agfa!
4042
const bitsPerEntry = Math.max(...voiLUT.lut).toString(2).length;
4143
const shift = bitsPerEntry - 8;
@@ -49,8 +51,10 @@ function generateNonLinearVOILUT (voiLUT) {
4951
} else if (modalityLutValue >= maxValueMapped) {
5052
return maxValue;
5153
}
52-
53-
return voiLUT.lut[modalityLutValue - voiLUT.firstValueMapped] >> shift;
54+
if( roundModalityLUTValues )
55+
return voiLUT.lut[Math.round(modalityLutValue) - voiLUT.firstValueMapped] >> shift;
56+
else
57+
return voiLUT.lut[modalityLutValue - voiLUT.firstValueMapped] >> shift;
5458
};
5559
}
5660

@@ -61,13 +65,14 @@ function generateNonLinearVOILUT (voiLUT) {
6165
* @param {Number} windowWidth Window Width
6266
* @param {Number} windowCenter Window Center
6367
* @param {LUT} [voiLUT] Volume of Interest Lookup Table Object
68+
* @param {Boolean} roundModalityLUTValues Do a Math.round of modality lut to compute non linear voilut
6469
*
6570
* @return {VOILUTFunction} VOI LUT mapping function
6671
* @memberof VOILUT
6772
*/
68-
export default function (windowWidth, windowCenter, voiLUT) {
73+
export default function (windowWidth, windowCenter, voiLUT, roundModalityLUTValues) {
6974
if (voiLUT) {
70-
return generateNonLinearVOILUT(voiLUT);
75+
return generateNonLinearVOILUT(voiLUT, roundModalityLUTValues);
7176
}
7277

7378
return generateLinearVOILUT(windowWidth, windowCenter);

0 commit comments

Comments
 (0)