Open Zaid-Safadi opened 6 years ago
For debugging purposes, setting the "useAlphaChannel" in the renderGrayscaleImage.getRenderCanvas to false would fix the issue since this causes cornerstone to explicitly reset the alpha channel.
@Zaid-Safadi, do you have a proposed fix? Would it help if we added an explicit method to reset the alpha channel?
@dannyrb this is what I use externally to fix this:
function resetRenderCanvase(element) {
const enabledElement = cornerstone.getEnabledElement(element);
enabledElement.renderingTools.colormapId = undefined;
enabledElement.renderingTools.colorLut = undefined;
const renderCanvas = enabledElement.renderingTools.renderCanvas;
const canvasContext = renderCanvas.getContext('2d');
// NOTE - we need to fill the render canvas with white pixels since we
// control the luminance using the alpha channel to improve rendering performance.
canvasContext.fillStyle = 'white';
canvasContext.fillRect(0, 0, renderCanvas.width, renderCanvas.height);
const renderCanvasData = canvasContext.getImageData(0, 0, renderCanvas.width, renderCanvas.height);
enabledElement.renderingTools.renderCanvasContext = canvasContext;
enabledElement.renderingTools.renderCanvasData = renderCanvasData;
}
Which is really taken from cornerstone here: https://github.com/cornerstonejs/cornerstone/blob/a1f0caf7e745bda4fd2b2687adc8746546a9a7ca/src/rendering/initializeRenderCanvas.js#L9-L27
So technically we can expose this method externally but maybe adding a method called "resetColomap" might be more suitable?
How to reproduce:
Apply colormap to an image by setting the viewport as in the "falseColorMapping" example:
Try to reset the colormap by setting the viewport.colormap to empty string *notice that setting to null won't actually reset the colormap since cornerstone copies from existing viewport when a property is null (possible issue related to #304)
*please ignore the colorbar as this doesn't reflect the reset in the example