DICOM image and overlay rendering for Node.js and browser using dcmjs
npm install dcmjs-imaging[![NPM version][npm-version-image]][npm-url] [![NPM downloads][npm-downloads-image]][npm-url] [![build][build-image]][build-url] [![MIT License][license-image]][license-url]
js
// Import objects in Node.js
const dcmjsImaging = require('dcmjs-imaging');
const { DicomImage, NativePixelDecoder } = dcmjsImaging;
// Import objects in Browser
const { DicomImage, NativePixelDecoder } = window.dcmjsImaging;
// Optionally register native decoders WebAssembly.
// If native decoders are not registered, only
// uncompressed syntaxes would be able to be rendered.
await NativePixelDecoder.initializeAsync();
// Create an ArrayBuffer with the contents of the DICOM P10 byte stream.
const image = new DicomImage(arrayBuffer);
// Render image.
const renderingResult = image.render();
// Rendered pixels in an RGBA ArrayBuffer.
const renderedPixels = renderingResult.pixels;
// Rendered width.
const width = renderingResult.width;
// Rendered height.
const height = renderingResult.height;
`
#### Advanced image rendering
`js
// Import objects in Node.js
const dcmjsImaging = require('dcmjs-imaging');
const { DicomImage, WindowLevel, NativePixelDecoder } = dcmjsImaging;
const { StandardColorPalette } = dcmjsImaging.constants;
// Import objects in Browser
const { DicomImage, WindowLevel, NativePixelDecoder } = window.dcmjsImaging;
const { StandardColorPalette } = window.dcmjsImaging.constants;
// Create native decoders WebAssembly initialization options.
const initOpts = {
// Optionally, provide the path or URL to WebAssembly module.
// If empty or undefined, the module is trying to be resolved
// within the same directory.
webAssemblyModulePathOrUrl: undefined,
// Optional flag to enable native decoder message logging.
// If not provided, the native decoder message logging is disabled.
logNativeDecodersMessages: false
};
// Optionally register native decoders WebAssembly.
// If native decoders are not registered, only
// uncompressed syntaxes would be able to be rendered.
await NativePixelDecoder.initializeAsync(initOpts);
// Create an ArrayBuffer with the contents of the DICOM P10 byte stream.
const image = new DicomImage(arrayBuffer);
// Create image rendering options.
const renderingOpts = {
// Optional frame index, in case of multiframe datasets.
// If not provided, the first frame is rendered.
frame: 0,
// Optional user-provided window/level.
// If not provided, the rendering pipeline calculates it
// from DICOM tag information or pixel values.
windowLevel: new WindowLevel(windowWidth, windowLevel),
// Optional flag to indicate whether overlays should be rendered.
// If not provided, the overlays are rendered.
renderOverlays: true,
// Optional flag to indicate whether histograms should be calculated.
// If not provided, the histograms are not calculated.
calculateHistograms: false,
// Optional standard color palette.
// If not provided, the grayscale palette is used.
colorPalette: StandardColorPalette.Grayscale
};
// Render image.
const renderingResult = image.render(renderingOpts);
// Rendered pixels in an RGBA ArrayBuffer.
const renderedPixels = renderingResult.pixels;
// Rendered frame index.
const frame = renderingResult.frame;
// Rendered width.
const width = renderingResult.width;
// Rendered height.
const height = renderingResult.height;
// Window/level used to render the pixels.
// In case of color images, windowLevel should not be present.
const windowLevel = renderingResult.windowLevel;
// Array of calculated per-channel histograms.
// In case calculateHistograms rendering option is false
// histograms should not be present.
const histograms = renderingResult.histograms;
// Color palette used to render the pixels.
// In case of color images, colorPalette should not be present.
const colorPalette = renderingResult.colorPalette;
``