百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
D

dicomParser

> DevOps
开源

用于 DICOM 第 10 部分数据的 JavaScript 解析器

753 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

用于 DICOM 第 10 部分数据的 JavaScript 解析器

[![NPM version][npm-version-image]][npm-url] [![NPM downloads][npm-downloads-image]][npm-url] [![MIT License][license-image]][license-url] [![Build Status][travis-image]][travis-url] [![Coverage Status][coverage-image]][coverage-url]

dicomParser

dicomParser is a lightweight library for parsing DICOM P10 byte streams, as well as raw (not encapsulated in part 10) byte streams, in modern HTML5 based web browsers (IE10+), Node.js and Meteor. dicomParser is fast, easy to use and has no required external dependencies.

Live Examples

The best way to see the power of this library is to actually see it in use. A number of live examples are included that are not only useful but also show how to use dicomParser. Click here for a list of all live examples Make sure you try out the DICOM Dump with Data Dictionary which is a very useful tool and excellent example of most features.

Community

Have questions? Try posting on our google groups forum.

Install

Get a packaged source file:

  • dicomParser.js
  • dicomParser.min.js

Or install via NPM:

npm install dicom-parser

Or install via atmosphere for Meteor applications

meteor add chafey:dicom-parser

  • Note - make sure you install pako if you need to support the Deflated Explicit VR Little Endian transfer syntax

Usage

…

See the live examples for more in depth usage of the library

Note that actually displaying DICOM images is quite complex due to the variety of pixel formats and compression algorithms that DICOM supports. If you are interested in displaying images, please take a look at the cornerstone library and the cornerstoneWADOImageLoader which uses this library to extract the pixel data from DICOM files and display the images with cornerstone library. You can find the actual code that extracts pixel data using this library here.

Options

dicomParser.parseDicom accepts an optional second argument that is an options object. The accepted properties are:

TransferSyntaxUID

A string value used as the default transfer syntax uid for parsing raw DICOM (not encapsualted in Part 10). For raw DICOM files, this value should be the LEI UID value.

untilTag

A tag in the form xggggeeee (where gggg is the hexadecimal group number and eeee is the hexadecimal element number, e.g. 'x7fe00010') that specifies the final tag to parse. Any tags occurring after this in the file will be ignored. Useful for partial reading of byte streams.

vrCallback

A callback that, given a tag, will return the two-character Value Representation associated with that tag (see PS 3.5 of the DICOM standard for more information). It may return undefined to indicate that the VR was not provided.

inflater

A callback that given the underlying byteArray and position of the deflated buffer returns a byteArray containing the DICOM P10 header and inflated data set concatenated together.

Key Features

  • Parses all known valid DICOM Part 10 byte arrays
    • Explicit and implicit
    • Little endian and big endian
    • Deflated Explicit VR Little Endian transfer syntax
      • Uses zlib when running node.js
      • requires pako in web browsers
      • has callback to support use of other inflate libraries
  • Supports all VR's including sequences
  • Supports elements with undefined length
  • Supports sequence items with undefined length
  • Provides functions to convert from all VR types to native Javascript types
  • Does not require a data dictionary
  • Designed for use in the browser
  • Each element exposes the offset and length of its data in the underlying byte stream
  • Packaged using the module pattern, as an AMD module and as a CommonJS module for Node.js
  • No external dependencies
  • Supports extraction of encapsulated pixel data frames
    • Basic Offset Table decoded
    • Fragments decoded
    • Function to extract image frame when basic offset table is present
    • Function to extract image frame from fragments when no basic offset table is present
  • Convenient utility functions to parse strings formatted in DA, TM and PN VRs and return JavaScript objects
  • Convenient utility function to create a string version of an explicit element
  • Convenient utility function to convert a parsed explicit dataSet into a javascript object
  • Convenient utility function to generate a basic offset table for JPEG images
  • Supports reading incomplete/partial byte streams
    • By specifying a tag to stop reading at (e.g. parseDicom(byteArray, {untilTag: "x7fe00010"}); )
    • By returning the elements parsed so far in the exception thrown during a parse error (the elements parsed will be in the dataSet property of the exception)
  • Supports reading from Uint8Arrays and Node.js Buffers

Build System

This project uses Webpack to build the software.

Pre-requisites:

NodeJs - click to visit web site for installation instructions.

Common Tasks

Update dependencies (after each pull):

npm install

Running the build:

npm run build

Automatically running the build and unit tests after each source change:

npm run watch

Publish

This library uses semantic-release to publish packages. The syntax of commits against the master branch determine how the new version calculated.

Example Commit
Release Type




fix(pencil): stop graphite breaking when too much pressure applied
Patch Release




feat(pencil): add 'graphiteWidth' option
Feature Release





  perf(pencil): remove graphiteWidth option

  

  BREAKING CHANGE: The graphiteWidth option has been removed. 
  The default graphite width of 10mm is always used for performance reasons.


  Major Breaking Release

Backlog

Future:

  • Add unit tests for sequence parsing functionality and encapsulated pixel frames
  • Figure out how to automatically generate documentation from the source (jsdoc)
  • Optimize findItemDelimitationItemAndSetElementLength() for speed
  • Optimize functions in byteArrayParser.js for speed
  • Add example that allows you to compare two sop instances against each other
  • Figure out how to not have a global dicomParser object when used with an AMD loader
  • See what needs to be done to support different character sets (assumes ASCII currently)
  • Support for parsing from streams on Node.js and Meteor
  • Switch to JavaScript ES6
  • Separate the parsing logic from the dataSet creation logic (e.g. parsing generates events which dataSet creation logic creates the dataSet from). Similar concept to SAX parsers.
    • dataSet creation logic could filter out unwanted tags to improve performance of parse
    • dataSet creation logic could defer creation of sequence dataSets to improve performance of parse
  • Function to parse non P10 byte streams given the byte stream and the transfer syntax
  • Support for encrypted dicom

Contributors

  • @neandrake for help with getting Node.js support
  • @ggerade for implementing support for floats/doubles with VM > 1
  • @yagni for bug fix related to parsing implicit little endian files and big endian support
  • @snagytx, @doncharkowsky - for bug fix related to reading encapsulated frames
  • @bbunderson, @jpambrun - bug fix for reading encapsulated frames
  • @henryqdineen, [email protected] - bug report for sequences with undefined lengths and zero items
  • @swederik - bug fixes on sequences with undefined lengths and zero items
  • @jkrot - performance enhancement in byteArrayParser
  • @cancan101 - issue related to multi-frame with multiple fragments and no basic offset table

Why another Javascript DICOM parsing library?

While building the WADO Image Loader for cornerstone, I couldn't find a Javascript DICOM parser that exactly met my needs. DICOM really isn't that hard to parse so I figured I would just make my own. Here are some of the key things that I really wanted out of a DICOM library that I am hoping to deliver:

  • License is extremely liberal so it could be used in any type of project
  • Only deals with parsing DICOM - no code to actually display the images
  • Designed to work well in a browser (modern ones at least)
  • Follows modern javascript best practices
  • Has documentation and examples on how to use it
  • Does not hide the underlying data stream from you
  • Does not require a data dictionary
  • Decodes individual elements "on demand" - this goes with not needing a data dictionary
  • Code guards against corrupt or invalid data streams by sanity checking lengths and offsets
  • Does not depend on any external dependencies - just drop it in and go
  • Has unit tests
  • Code is easy to understand

Interested in knowing why the above goals are important to me? Here you go:

License is extremely liberal so it could be used in any type of project

DICOM is an open standard and parsing it is easy enough that it should be freely available for all types of products - personal, open source and commercial. I am hoping that the MIT license will help it see the widest possible adoption (which will in the end help the most patients). I will dual license it under GPL if someone asks.

Only deals with parsing DICOM - no code to actually display the images

I am a big believer in small reusable pieces of software and loose coupling. There is no reason to tightly couple the parser with image display. I hope that keeping this library small and simple will help it reach the widest adoption.

Designed to work well in a browser (modern ones at least)

There are some good javascript DICOM parsing libraries available for server development on node.js but they won't automatically work in a browser. I needed a library that let me easily parse WADO responses and I figured others would also prefer a simple library to do this with no dependencies. The library does make use of the ArrayBuffer object which is widely supported except for IE (it is available on IE10+). I have no current plans to add support for older versions of IE but would be open to contributions if someone wants to do the work.

Follows modern javascript best practices

This of course means different things to different people but I have found great benefit from making sure my javascript passes jshint and leveraging the module pattern. I also have a great affinity to AMD modules but I understand that not everyone wants to use them. So for this library I am shooting for simply making sure the code uses the module pattern and passes jshint.

Has documentation and examples on how to use it

Do I really need to convince you that this is needed?

Does not hide the underlying data stream from you

I have used many DICOM parsing libraries over the years and most of them either hide the underlying byte stream from you or make it difficult

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScriptdicomjavascriptnci-itcr

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类DevOps
定价开源

> 相关工具

D
Docker
容器化平台,标准化应用交付
G
GitHub Actions
GitHub 原生 CI/CD 工作流
N
Nginx
高性能 Web 服务器与反向代理