DICOM file and dataset transcoding for Node.js and browser using dcmjs
npm install dcmjs-codecs[![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 dcmjsCodecs = require('dcmjs-codecs');
const { NativeCodecs, Transcoder } = dcmjsCodecs;
const { TransferSyntax } = constants;
// Import objects in Browser
const { NativeCodecs, Transcoder } = window.dcmjsCodecs;
const { TransferSyntax } = constants;
// Register native codecs WebAssembly.
await NativeCodecs.initializeAsync();
// Create an ArrayBuffer with the contents of the DICOM P10 byte stream.
const transcoder = new Transcoder(arrayBuffer);
// Transcode to a different transfer syntax UID.
transcoder.transcode(TransferSyntax.JpegLosslessProcess14V1);
// Get the transcoded DICOM P10 byte stream in an ArrayBuffer.
const transcodedArrayBuffer = transcoder.getDicomPart10();
`
#### Advanced image transcoding
`js
// Import objects in Node.js
const dcmjsCodecs = require('dcmjs-codecs');
const { NativeCodecs, Transcoder } = dcmjsCodecs;
const { Jpeg2000ProgressionOrder, TransferSyntax } = constants;
// Import objects in Browser
const { NativeCodecs, Transcoder } = window.dcmjsCodecs;
const { Jpeg2000ProgressionOrder, TransferSyntax } = constants;
// Create native codecs 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 codecs informational message logging.
// If not provided, the native codecs informational message logging is disabled.
logCodecsInfo: false,
// Optional flag to enable native codecs trace message logging.
// If not provided, the native codecs trace message logging is disabled.
logCodecsTrace: false
};
await NativeCodecs.initializeAsync(initOpts);
// Create an ArrayBuffer with the contents of the DICOM P10 byte stream.
const transcoder = new Transcoder(arrayBuffer);
// Create encoding and decoding options.
const encodingDecodingOpts = {
// JPEG encoding params
// Optional JPEG quality, in case of JPEG baseline encoding.
// Sets the libjpeg jpeg_set_quality quality input variable.
quality: 90,
// JPEG-LS encoding params
// Optional JPEG-LS quality, in case of JPEG-LS lossy encoding.
// Sets the charls allowedLossyError variable.
allowedLossyError: 10,
// JPEG 2000 and HT-JPEG 2000 encoding params
// Optional JPEG progression order, in case of JPEG 2000 and HT-JPEG 2000 encoding.
progressionOrder: Jpeg2000ProgressionOrder.Lrcp,
// Optional JPEG 2000 quality, in case of JPEG 2000 lossy encoding.
// Sets the openjpeg tcp_rates[0] variable.
rate: 20
};
// Transcode to a different transfer syntax UID.
transcoder.transcode(TransferSyntax.Jpeg2000Lossless, encodingDecodingOpts);
// Get the transcoded DICOM P10 byte stream in an ArrayBuffer.
const transcodedArrayBuffer = transcoder.getDicomPart10();
``