Crate dicom_object[][src]

This crate contains a high-level abstraction for reading and manipulating DICOM objects. At this level, objects are comparable to a dictionary of elements, in which some of them can have DICOM objects themselves. The end user should prefer using this abstraction when dealing with DICOM objects.

Examples

Loading a DICOM file and reading some attributes by their standard alias:

use dicom_object::open_file;
let obj = open_file("0001.dcm")?;
let patient_name = obj.element_by_name("PatientName")?.to_str()?;
let modality = obj.element_by_name("Modality")?.to_str()?;

Elements can also be fetched by tag. Methods are available for converting the element’s DICOM value into something more usable in Rust.

let patient_date = obj.element(Tag(0x0010, 0x0030))?.to_date()?;
let pixel_data_bytes = obj.element(Tag(0x7FE0, 0x0010))?.to_bytes()?;

Finally, DICOM objects can be serialized back into DICOM encoded bytes. A method is provided for writing a file DICOM object into a new DICOM file.

obj.write_to_file("0001_new.dcm")?;

This method requires you to write a file meta table first. When creating a new DICOM object from scratch, use a FileMetaTableBuilder to construct the file meta group, then use with_meta or with_exact_meta:

let file_obj = obj.with_meta(
    FileMetaTableBuilder::new()
        // Implicit VR Little Endian
        .transfer_syntax("1.2.840.10008.1.2")
        // Computed Radiography image storage
        .media_storage_sop_class_uid("1.2.840.10008.5.1.4.1.1.1")
)?;
file_obj.write_to_file("0001_new.dcm")?;

In order to write a plain DICOM data set, use one of the various write_dataset methods.

// build your object
let mut obj = InMemDicomObject::create_empty();
let patient_name = DataElement::new(
    Tag(0x0010, 0x0010),
    VR::PN,
    dicom_value!(Str, "Doe^John"),
);
obj.put(patient_name);

// write the object's data set
let mut serialized = Vec::new();
let ts = dicom_transfer_syntax_registry::entries::EXPLICIT_VR_LITTLE_ENDIAN.erased();
obj.write_dataset_with_ts(&mut serialized, &ts)?;
assert!(!serialized.is_empty());

Re-exports

pub use crate::file::from_reader;
pub use crate::file::open_file;
pub use crate::mem::InMemDicomObject;
pub use crate::meta::FileMetaTable;
pub use crate::meta::FileMetaTableBuilder;

Modules

file
loader
mem

This module contains the implementation for an in-memory DICOM object.

meta

Module containing data structures and readers of DICOM file meta information tables.

pixeldata

Module for the pixel data trait and implementations.

tokens

Convertion of DICOM objects into tokens.

Structs

FileDicomObject

A root DICOM object retrieved from a standard DICOM file, containing additional information from the file meta group in a separate table value.

StandardDataDictionary

A data dictionary which consults the library’s global DICOM attribute registry.

Tag

The data type for DICOM data element tags.

Enums

Error

Constants

IMPLEMENTATION_CLASS_UID

The current implementation class UID generically referring to DICOM-rs.

IMPLEMENTATION_VERSION_NAME

The current implementation version name generically referring to DICOM-rs.

Traits

DicomObject

Trait type for a DICOM object. This is a high-level abstraction where an object is accessed and manipulated as dictionary of entries indexed by tags, which in turn may contain a DICOM object.

Type Definitions

DefaultDicomObject

The default implementation of a root DICOM object.

Result
RootDicomObjectDeprecated

A root DICOM object contains additional meta information about the object in a separate table.