Skip to content

Commit

Permalink
fix: Correct float access to lut array (#302) (#303)
Browse files Browse the repository at this point in the history
* Correct float access to lut array (#302)

* Fix performance issue (#302)

Co-authored-by: pleduff <pierre.leduff@medecom.fr>
  • Loading branch information
pierreldff and pleduff committed Sep 13, 2021
1 parent 7acd99a commit 2cac920
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/internal/generateLut.js
Expand Up @@ -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++) {
Expand Down
17 changes: 11 additions & 6 deletions src/internal/getVOILut.js
Expand Up @@ -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;
Expand All @@ -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;
};
}

Expand All @@ -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);
Expand Down

0 comments on commit 2cac920

Please sign in to comment.