diff --git a/src/internal/generateLut.js b/src/internal/generateLut.js index 43503746..d9f156af 100644 --- a/src/internal/generateLut.js +++ b/src/internal/generateLut.js @@ -28,8 +28,9 @@ export default function (image, windowWidth, windowCenter, invert, modalityLUT, } const lut = image.cachedLut.lutArray; + var slopeOrInterceptAreFloat = !!(image.slope % 1) || !!(image.intercept % 1); const mlutfn = getModalityLUT(image.slope, image.intercept, modalityLUT); - const vlutfn = getVOILUT(windowWidth, windowCenter, voiLUT); + const vlutfn = getVOILUT(windowWidth, windowCenter, voiLUT, slopeOrInterceptAreFloat); if (invert === true) { for (let storedValue = minPixelValue; storedValue <= maxPixelValue; storedValue++) { diff --git a/src/internal/getVOILut.js b/src/internal/getVOILut.js index baeac7dc..3bd9c0c3 100644 --- a/src/internal/getVOILut.js +++ b/src/internal/getVOILut.js @@ -30,12 +30,14 @@ function generateLinearVOILUT (windowWidth, windowCenter) { /** * Generate a non-linear volume of interest lookup table * - * @param {LUT} voiLUT Volume of Interest Lookup Table Object + * @param {LUT} voiLUT Volume of Interest Lookup Table Object + * @param {Boolean} roundModalityLUTValues Do a Math.round of modality lut to compute non linear voilut + * * @returns {VOILUTFunction} VOI LUT mapping function * @memberof VOILUT */ -function generateNonLinearVOILUT (voiLUT) { +function generateNonLinearVOILUT (voiLUT, roundModalityLUTValues) { // We don't trust the voiLUT.numBitsPerEntry, mainly thanks to Agfa! const bitsPerEntry = Math.max(...voiLUT.lut).toString(2).length; const shift = bitsPerEntry - 8; @@ -49,8 +51,10 @@ function generateNonLinearVOILUT (voiLUT) { } else if (modalityLutValue >= maxValueMapped) { return maxValue; } - - return voiLUT.lut[modalityLutValue - voiLUT.firstValueMapped] >> shift; + if( roundModalityLUTValues ) + return voiLUT.lut[Math.round(modalityLutValue) - voiLUT.firstValueMapped] >> shift; + else + return voiLUT.lut[modalityLutValue - voiLUT.firstValueMapped] >> shift; }; } @@ -61,13 +65,14 @@ function generateNonLinearVOILUT (voiLUT) { * @param {Number} windowWidth Window Width * @param {Number} windowCenter Window Center * @param {LUT} [voiLUT] Volume of Interest Lookup Table Object + * @param {Boolean} roundModalityLUTValues Do a Math.round of modality lut to compute non linear voilut * * @return {VOILUTFunction} VOI LUT mapping function * @memberof VOILUT */ -export default function (windowWidth, windowCenter, voiLUT) { +export default function (windowWidth, windowCenter, voiLUT, roundModalityLUTValues) { if (voiLUT) { - return generateNonLinearVOILUT(voiLUT); + return generateNonLinearVOILUT(voiLUT, roundModalityLUTValues); } return generateLinearVOILUT(windowWidth, windowCenter);