const pixelArray = [11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11..]
if (pixelArray != null)
{
for (let i = 0; i < pixelArray.length; i++)
{
let pixel = pixelArray[i];
pixel = applyWindowLevel(pixel, imageWC, imageWW);
pixel = lutArray[pixel];
// let red = (pixel & 0x00ff0000) >> 16;
let v = i * 4;
imageData[v] = pixel & 0xff;
imageData[v + 1] = (pixel >>> 8) & 0xff;
imageData[v + 2] = (pixel >>> 16) & 0xff;
imageData[v + 3] = 255;
}
// offscreenCtx.imageSmoothingEnabled = true;
offscreenCtx.putImageData(g, 0, 0);
}
function applyWindowLevel(value, windowCenter, windowWidth)
{
recalculate(windowCenter, windowWidth);
if (value <= windowStart)
value = minimumOutputValue;
else if (value > windowEnd)
value = maximumOutputValue;
else
{
value = Math.round((((value - windowCenterMin05) / windowWidthMin1) + 0.5) * 255.0);
}
return value;
}
var minimumOutputValue = 0;
var maximumOutputValue = 255;
function recalculate(windowCenter, windowWidth)
{
if (!valid)
{
windowCenterMin05 = windowCenter - 0.5;
windowWidthMin1 = windowWidth - 1;
windowWidthDiv2 = windowWidthMin1 / 2;
windowStart = (windowCenterMin05 - windowWidthDiv2);
windowEnd = (windowCenterMin05 + windowWidthDiv2);
valid = true;
}
}
Width: <input id="text1" type="text" />
Center: <input id="text2" type="text" />
<input id="Button1" type="button" value="Apply" onclick="applyCustomWLCust();" /></br>
Time Required: <input id="text3" type="text" />
<canvas style="height: 500px; width: 500px; display1: none; background-color: black;
border: 1px solid red;" id="offscreenCanvas"></canvas>
I have applied window leveling on a Canvas medical image (CR). I receive a pixel array from a C# Component. When the button is clicked, I call the function applyCustomWLCust(); All processes are executed in this function and yield perfect results. For window leveling, bit shifting is used which takes around 585ms. I need to reduce this processing time; any suggestions or solutions would be greatly appreciated.