#dicom #data #pixel #object #medical-imaging #decoding #convert

bin+lib dicom-pixeldata

A high-level API for decoding DICOM objects into images and ndarrays

11 releases

0.2.2 Nov 21, 2023
0.2.0 Jul 23, 2023
0.1.5 Dec 12, 2022
0.1.4 Oct 23, 2022
0.1.0-rc.1 Nov 18, 2021

#414 in Images

Download history 422/week @ 2023-12-11 497/week @ 2023-12-18 27/week @ 2023-12-25 433/week @ 2024-01-01 513/week @ 2024-01-08 507/week @ 2024-01-15 346/week @ 2024-01-22 513/week @ 2024-01-29 400/week @ 2024-02-05 431/week @ 2024-02-12 411/week @ 2024-02-19 204/week @ 2024-02-26 371/week @ 2024-03-04 598/week @ 2024-03-11 363/week @ 2024-03-18 183/week @ 2024-03-25

1,523 downloads per month
Used in 4 crates

MIT/Apache

2.5MB
39K SLoC

DICOM-rs pixeldata

CratesIO Documentation

This sub-project is directed at users of the DICOM-rs ecosystem. It provides constructs for handling DICOM pixel data and is responsible for decoding pixel data elements into images or multi-dimensional arrays.

This crate is part of the DICOM-rs project.


lib.rs:

This crate contains the DICOM pixel data handlers and is responsible for decoding various forms of native and compressed pixel data, such as JPEG lossless, and convert it into more usable data structures.

dicom-pixeldata currently supports a small, but increasing number of DICOM image encodings in pure Rust. As a way to mitigate the current gap, this library has an integration with GDCM bindings for an extended range of encodings. This integration is behind the Cargo feature "gdcm", which requires CMake and a C++ compiler.

dicom-pixeldata = { version = "0.1", features = ["gdcm"] }

Once the pixel data is decoded, the decoded data can be converted to:

This conversion includes eventual Modality and value of interest (VOI) transformations.

WebAssembly support

This library works in WebAssembly with the following two measures:

  • Ensure that the "gdcm" feature is disabled. This allows the crate to be compiled for WebAssembly albeit at the cost of supporting a lesser variety of compression algorithms.
  • And either set up wasm-bindgen-rayon or disable the rayon feature.

Examples

To convert a DICOM object into a dynamic image (requires the image feature):

use dicom_object::open_file;
use dicom_pixeldata::PixelDecoder;
let obj = open_file("dicom.dcm")?;
let image = obj.decode_pixel_data()?;
let dynamic_image = image.to_dynamic_image(0)?;
dynamic_image.save("out.png")?;

To convert a DICOM object into an ndarray (requires the ndarray feature):

use dicom_object::open_file;
use dicom_pixeldata::PixelDecoder;
use ndarray::s;
let obj = open_file("rgb_dicom.dcm")?;
let pixel_data = obj.decode_pixel_data()?;
let ndarray = pixel_data.to_ndarray::<u16>()?;
let red_values = ndarray.slice(s![.., .., .., 0]);

In order to parameterize the conversion, pass a conversion options value to the _with_options variant methods.

use dicom_object::open_file;
use dicom_pixeldata::{ConvertOptions, PixelDecoder, VoiLutOption};
let obj = open_file("dicom.dcm")?;
let image = obj.decode_pixel_data()?;
let options = ConvertOptions::new()
    .with_voi_lut(VoiLutOption::Normalize)
    .force_8bit();
let dynamic_image = image.to_dynamic_image_with_options(0, &options)?;

See ConvertOptions for the options available, including the default behavior for each method.

Dependencies

~7–16MB
~243K SLoC