Javascript library for reading and writing DICOM files in desktop, cloud and browser applications. The following frameworks are supported:
- Browser (Javascript)
- NodeJS ESM
- NodeJS CJS
- DicomReader - DICOM reader and parser, with image extraction capabilities
- DicomWriter - DICOM creator and serializer
- DicomElement - Main building block for DICOM files
- DICOM_TAG - Collection constants for commonly used DICOM tags
- DicomDictionary - Contains VR and description for most used DICOM tags
- PixelSpacing - Used for calibration purposes
Detailed documentation can be read here
Add a reference to the script into your html header section:
<head>
<script src="Efferent.Dicom.js"></script> <!-- Full -->
<script src="Efferent.Dicom.min.js"></script> <!-- Minified -->
</head>If preferred, you can use a CDN url like:
<head>
<script src="https://cdn.jsdelivr.net/npm/efferent-dicom@1/dist/Efferent.Dicom.js"></script> <!-- Full -->
<script src="https://cdn.jsdelivr.net/npm/efferent-dicom@1/dist/Efferent.Dicom.min.js"></script> <!-- Minified -->
</head>You can also import the library using bundlers such as Webpack, Rollup, or Vite.
The library is published on npm as efferent-dicom.
ESM (ECMAScript Modules)
If your project uses "type": "module" in package.json or has .mjs files:
import { DicomReader, DICOM_TAG as TAG } from 'efferent-dicom';CommonJS (require syntax)
If your project uses the default CommonJS module system:
const { DicomReader, DICOM_TAG: TAG } = require('efferent-dicom');- In CJS, destructuring syntax uses
DICOM_TAG: TAGto rename the constant. - In ESM, you can directly alias using
as TAG.
import fs from 'fs';
import { DicomReader, DICOM_TAG as TAG } from 'efferent-dicom';
const data = fs.readFileSync('example.dcm');
const parser = new DicomReader(new Uint8Array(data.buffer));
console.log(parser.DicomTags[TAG.PATIENT_NAME]);If working with typescript, install efferent-dicom npm module in your package.json.
This way, TypeScript automatically finds the right .d.ts whether the developer is using:
- Node:
import { something } from "efferent-dicom"; - Browser build:
import "efferent-dicom/browser";
If not using npm packages, include Efferent.Dicom.d.ts in your tsconfig.json file:
"include": [
"./lib/Efferent.Dicom.d.ts",
// Other files
]There are two demo applications, included in this repository:
Run node/dicomdump.js to print in the console detailed DICOM tags, using the command:
node ./demo/node/dicomdump.js <dicom file>Open demo/html/index.html for an interactive demo that can read a DICOM file (.dcm extension), show a summary and a picture (only for .50 JPEG transfer syntax), as well as detailed DICOM tags
