cornerstonejs / cornerstone

JavaScript library to display interactive medical images including but not limited to DICOM
https://docs.cornerstonejs.org/
MIT License
2.06k stars 598 forks source link

Floating point lookup table support #297

Closed tostein closed 6 years ago

tostein commented 6 years ago

Description: I was wondering if there is any support for floating point based image data (like a DICOM parametric map) to use a colormap.

Problem: Usage of colormaps within a image stack for floating point based image data leads to errors within storedPixelDataToCanvasImageDataColorLUT.js because index based array access requires integer values.

Proposal: If there is no solution yet, one could find for a given floating point value the closest integers from existing lookup-tables and do a linear interpolation between the two colors.

Something like the following would fit into the named ImageDataColorLUT.js:

      let value pixelData[storedPixelDataIndex++];
      let cLeft = clut[Math.floor(value)];
      let cRight = clut[Math.ceil(value)];
      canvasImageDataData[canvasImageDataIndex++] = parseInt((cleft[0] + cRight[0])/2.0);
      canvasImageDataData[canvasImageDataIndex++] = parseInt((cleft[1] + cRight[1])/2.0);
      canvasImageDataData[canvasImageDataIndex++] = parseInt((cleft[2] + cRight[2])/2.0);
      canvasImageDataData[canvasImageDataIndex++] = parseInt((cleft[3] + cRight[3])/2.0);

It must be checked that typeof pixel.Data == Float32Array

For now i am rounding my values to integers and use the lookup tables. But that should be better shouldn't it?

@pieper

swederik commented 6 years ago

Hi Tobias,

How are you loading this image? With the WADO Image Loader we convert any float pixel data to integers and use that for rendering when the image is loaded:

https://github.com/cornerstonejs/cornerstoneWADOImageLoader/blob/da4c03933b4b6f634c59614a6aa1a479980f2968/src/imageLoader/createImage.js#L18

The float pixel data remains, and is kept in the floatPixelData property: https://github.com/cornerstonejs/cornerstoneWADOImageLoader/blob/da4c03933b4b6f634c59614a6aa1a479980f2968/src/imageLoader/createImage.js#L132

So I am a bit surprised that the issues you mention above exist, unless you are using a custom image loader. In that case, it's probably easiest to do the same as what we are doing in the WADO Image Loader.

tostein commented 6 years ago

Thanks for your fast answer. Yes i am using a custom loader. I will considering using the WADO image loader instead.

pieper commented 6 years ago

@NussknackerXXL you could also just add the rescaling code to your custom loader.