Function: renderToImageDataCPU()
renderToImageDataCPU(
image,options):RenderToImageDataCPUResult
Renders a cornerstone image to RGBA pixel values with the CPU, with no canvas and no DOM. The function uses the same display pipeline as renderToCanvasCPU: modality LUT, VOI (window, VOI LUT sequence, sigmoid), invert, color and colormap. It does not apply the display transform (zoom, pan, rotation, flip).
The result has the size of viewport.displayedArea, which is the whole image by default. Set displayedArea to get a source region: tlhc and brhc are the first and the last pixel of the region, 1-based and inclusive, as in the canvas path. The result has one pixel for each image pixel of the region; a region pixel outside the image is opaque black. Scale the result, if necessary, after the call. The function does not limit the region size, so a caller that takes the region from a request must limit it.
The result is the same as the canvas of renderToCanvasCPU at the image size, with these differences:
- Each pixel is drawn onto a black background, so the alpha is always 255. For a pixel with an alpha below 255 (a colormap or an RGBA image), a value can differ by 1 from the canvas, because a canvas stores premultiplied alpha.
- For an image with only preScale.scaled, renderToCanvasCPU applies the rescale again, and this function does not (see image.isPreScaled below).
- The function does not correct non-square pixel spacing. Scale the result with image.columnPixelSpacing and image.rowPixelSpacing, if necessary.
- With no modality option, the function uses image.preScale.scalingParameters.modality, so a pre-scaled PT image gets the PET window. renderToCanvasCPU needs the modality argument.
A custom image.render function is not used.
Known limit, the same as renderToCanvasCPU: a pre-scaled non-PT image with fractional pixel values (for example a Float32Array with 0.5) renders the fractional pixels black, because the LUT has integer indices.
As the viewports and loadImageToCanvas do, the function sets image.isPreScaled from image.preScale.scaled. It also caches the LUT in image.cachedLut, writes image.stats, and sets a passed CPU colormap object to 256 colors. It does not change the other objects of options.
Parameters
• image: IImage
Cornerstone image object, with its pixel data loaded
• options: RenderToImageDataCPUOptions = {}
The modality and the viewport values to use
Returns
The RGBA pixel values, and the size of the displayed area (the whole image by default)
Throws
Error when displayedArea has no tlhc or brhc, is empty, or is not on whole pixels.
Throws
Error when viewport.colormap is a name with no CPU colormap, including a grayscale name such as 'Grayscale' or 'gray'. For grayscale, give no colormap, or null. renderToCanvasCPU has the same error.
Throws
TypeError when the image has no window and is a color image, has a VOI LUT, or is a PT image with a colormap that is not pre-scaled. renderToCanvasCPU has the same error.