Module Dicomm

module Dicomm: sig .. end
Non-blocking streaming DICOM data element decoder.

Dicomm is a non-blocking streaming decoder to decode DICOM data elements.

Consult the data model, features and limitations and examples of use.

Release 0.0.0-13-gaff23ca — Daniel Bünzli <daniel.buenzl>


Data model

type syntax = [ `BE_explicit | `File | `LE_explicit | `LE_implicit ] 
The type for transfer syntaxes. See Dicomm.decoder.
type vr = [ `AE
| `AS
| `AT
| `CS
| `DA
| `DS
| `DT
| `FD
| `FL
| `IS
| `LO
| `LT
| `OB
| `OF
| `OW
| `PN
| `SH
| `SL
| `SQ
| `SS
| `ST
| `TM
| `UI
| `UL
| `UN
| `US
| `UT ]
The type for value representations.
val pp_vr : Format.formatter -> vr -> unit
pp_vr ppf vr prints an unspecified representation of vr on ppf.
type tag 
The type for data elements tags.
module Tag: sig .. end
Data elements tags and data dictionary.
module Uid: sig .. end
Unique identifiers (UID).
type time = [ `Daytime of float | `Stamp of float * float option ] 
The type for representing times.
val pp_time : Format.formatter -> time -> unit
pp_time ppf t prints an unspecified representation of t on ppf.
type ('a, 'b) bigarray = ('a, 'b, Bigarray.c_layout) Bigarray.Array1.t 
The type for bigarrays.
type value = [ `Float32 of (float, Bigarray.float32_elt) bigarray
| `Float64 of (float, Bigarray.float64_elt) bigarray
| `Int16 of (int, Bigarray.int16_signed_elt) bigarray
| `Int32 of (int32, Bigarray.int32_elt) bigarray
| `String of [ `Many of string list | `One of string ]
| `Tag of [ `Many of Tag.t list | `One of Tag.t ]
| `Time of [ `Many of time list | `One of time ]
| `UInt16 of (int, Bigarray.int16_unsigned_elt) bigarray
| `UInt32 of (int32, Bigarray.int32_elt) bigarray
| `UInt8 of (int, Bigarray.int8_unsigned_elt) bigarray ]
The type for values. VR are mapped to cases as given below. This should be documented in VR cases but ocamldoc doesn't support documentation in polymporphic variants.
val pp_value : ?limit:int -> Format.formatter -> [< value ] -> unit
pp_value limit ppf v prints an unspecified textual representation of v on ppf. limit is the maximal number of printed element arrays.
type element = Tag.t * vr * value 
The type for data elements.
val pp_element : Format.formatter -> element -> unit
pp_element names ppf v prints and unspecified textual representation of v on ppf. If names is true (defaults to false
type lexeme = [ `E of element | `I | `Se of Tag.t | `Ss of Tag.t ] 
The type for DICOM lexemes. `Ss and `Se are respectively for starting and ending sequences of data elements items (SQ value representation).

A well-formed sequence of lexemes belongs to the language of the dicom grammar:

  dicom = `E e / `Es t *(`I dicom) `Ee t / dicom

A decoder returns only well-formed sequences of lexemes or `Errors are returned.

val pp_lexeme : Format.formatter -> [< lexeme ] -> unit
pp_lexeme names ppf l prints an unspecified textual representation of l on ppf.


type error = [ `Eoi of
[ `File_dicom_prefix
| `File_preamble
| `Reserved of Tag.t
| `Tag
| `Tag_or_eoi
| `Value of Tag.t
| `Value_length of Tag.t
| `Vr of Tag.t ]
| `File_syntax_unspecified
| `File_syntax_vr_not_uid of vr
| `Parse_file_dicom_prefix
| `Parse_float of Tag.t * string
| `Parse_int of Tag.t * string
| `Parse_time of Tag.t * string
| `Unknown_vr of Tag.t * string
| `Value_length_mismatch of Tag.t * int * int
| `Value_length_overflow of Tag.t
| `Value_length_undefined of Tag.t ]

The type for decoding errors.
val pp_error : Format.formatter -> [< error ] -> unit
pp_error e prints an unspecified representation of e on ppf.
type src = [ `Channel of Pervasives.in_channel | `Manual | `String of string ] 
The type for input sources. With a `Manual source the client must provide input with Dicomm.Manual.src.
type decoder 
The type for decoders.
val decoder : ?vr:(Tag.t -> vr) ->
syntax:syntax -> [< src ] -> decoder
decoder private_tag file src is a DICOM decoder that inputs DICOM data elements from src according to syntax.

If syntax is `File, the decoder first parses a DICOM file preamble and the DICM prefix reporting an error if it fails to do so. Decodes then return the DICOM file meta information and the decoder automatically switch to the right syntax for decoding the data object.

If decoding is done using the implicit syntax vr is called on tags that return None on Tag.vr to determine the value representation to use (defaults to fun _ -> `UN).

val decode : decoder ->
[ `Await | `End | `Error of error | `Lexeme of lexeme ]
decode d is:
val decoded_range : decoder -> int * int
decoded_range d is the range of bytes spanning the last `Lexeme or `Error decoded by d.
val decoder_src : decoder -> src
decoder_src d is d's input source.
val decoder_syntax : decoder -> syntax
decoder_syntax d is d's decoded syntax.
val pp_decode : Format.formatter ->
[< `Await | `End | `Error of error | `Lexeme of lexeme ] ->
pp_decode ppf v prints an unspecified representation of v on ppf.

Manual sources

module Manual: sig .. end
Manual sources.

Error recovery

After a decoding error, if best-effort decoding is performed. The following happens before continuing:

Features and limitations

On decoding:

Pixel data

On decoding for DICOM bitmap data, the pixel representation tag (0028,0103) is captured and if tag (7FE0, 0010) has a 16 bits representation the value is mapped to `UInt16 or `Int16 accordingly.