cornerstonejs / cornerstone

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

converting 8bit gray scale to rgba #564

Open meisterpeeps opened 2 years ago

meisterpeeps commented 2 years ago

I'd like to use an external library that performs image manipulation on canvas images and I have dicom images that are 8bit gray scale. The image.getPixelData function returns an 8 bit array of 0-255 ints representing gray scale, and the canvas requires an array that represents rgba. I figure that cornerstone is doing that conversion somewhere internally since it ultimately is drawn on the canvas. Is there a straightforward way to do that conversion with cornerstone?

chafey commented 2 years ago

Very straightforward - set RGB to the grayscale value. The code for this is here: https://github.com/cornerstonejs/cornerstone/blob/master/src/internal/storedPixelDataToCanvasImageDataRGBA.js