An easy-to-use Grassroots DICOM Library wrapper designed to convert DICOM files transfer syntaxes and photometric interpretation.
Usage
You need CMake to build GDCM Library.
Linux Ubuntu:
sudo apt-get install cmake
Windows & MacOS:
Download CMake directly from www.cmake.org/download page.
Quickstart
Copy this code and make sure you have a DICOM file to test (DICOM file samples).
use *;
use File;
use ;
// Read input file
let mut ibuffer = Vec new;
let mut ifile = open.unwrap;
ifile.read_to_end.unwrap;
// Transcode DICOM file
let obuffer = match pipeline ;
// Create output file and save
let mut ofile = create.unwrap;
ofile.write_all.unwrap;
How it works
The gdcm_conv library takes as input the content of the DICOM file (source: Vec). It reuse the source vector and allocate an estimated size to avoid duplicated memory. Because it don't know if it is going to compress or uncompress the final image, the default estimated length is of 3 * input file size. Is recommended to use an estimated calculation. If the allocated size is not enough, the library will re-allocate to the correct size and execute the transcoding, but it is running two times.
To estimate the output length you could use this aproximation:
- (0028,0100) bits_allocated
- (0028,0004) photometric_interpretation
- (0028,0008) number_of_frames
- (0028,0010) rows
- (0028,0011) columns
// MAX HEADER SIZE
const MAX_HEADER_SIZE: usize = 5000;
let a = match bits_allocated {
8 => 1,
16 => 2,
};
let b = match photometric_interpretation {
"MONOCHROME1" => 1,
"MONOCHROME2" => 1,
_ => 3,
};
let estimad_length = (a * b * rows * columns * number_of_frames) + MAX_HEADER_SIZE;
To execute the DICOM file conversion, it works like a pipeline with a first transfer syntax conversion (PRE-TRANSFER), a photometric conversion and a final transfer syntax conversion (POST-TRANSFER). If you set to None it don't execute the step. Usually, you will use only the first and/or second step.
In case you need to convert from JPEG Baseline (Process 1) 1.2.840.10008.1.2.4.50 with YBR_FULL or YBR_FULL_422 to JPEG2000 lossles, you must first change to Explicit Little Endian transfer syntax, then to an RGB photometric interpretation and finally to JPG2000, to avoid color interpretation issue.