Created
June 21, 2019 06:47
-
-
Save jdmichaud/a6e42fff8eba8a7707a97bfccd8d5889 to your computer and use it in GitHub Desktop.
Modality / VOI Lut
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function modalityLutFunctor(s, i) { | |
return (x) => s * x + i; | |
} | |
function voiLutFunctor(wc, ww, maxOutput, minOutput) { | |
const left = wc - ww / 2; | |
const right = wc + ww / 2; | |
const a = (maxOutput - minOutput) / (right - left); | |
const b = -left * a; | |
return (x) => a * x + b; | |
} | |
function computeBound(s, i, wc, ww) { | |
const left = wc - ww / 2; | |
const right = wc + ww / 2; | |
return { | |
min: (left - i) / s, | |
max: (right - i) / s, | |
} | |
} | |
function computeLut(s, i, wc, ww, maxOutput = 255, minOutput = 0) { | |
const modalityLut = modalityLutFunctor(s, i); | |
const voiLut = voiLutFunctor(wc, ww, maxOutput, minOutput); | |
const { min, max } = computeBound(s, i, wc, ww); | |
const lut = []; | |
for (let i = min; i < max + 1; ++i) { | |
lut[i - min] = Math.round(voiLut(modalityLut(i))); | |
} | |
return { min, max, lut }; | |
} | |
computeLut(2, 1, 10, 10); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment