|
NEP 4.0.0
NetCDF Expansion Pack
|
DICOM (Digital Imaging and Communications in Medicine) is the standard format for medical imaging objects such as CT, MR, XA, and ultrasound. NEP exposes single-frame and multi-frame DICOM images through the standard NetCDF API via a User-Defined Format (UDF) handler.
Transparent Access: Open DICOM files with nc_open() and read metadata, dimensions, and pixel data using standard NetCDF functions.
Dimension Mapping:
frame dimension (NumberOfFrames)row dimension (Rows)column dimension (Columns)sample dimension (SamplesPerPixel, if > 1)Data Variable: pixel_data with a type determined by BitsAllocated and PixelRepresentation:
NC_UBYTENC_BYTENC_USHORTNC_SHORTNC_UINTNC_INTGlobal Attributes: PatientName, PatientID, Modality, PhotometricInterpretation, TransferSyntaxUID, StudyInstanceUID, SeriesInstanceUID, SOPClassUID, SOPInstanceUID.
Variable Attributes: NumberOfFrames, SamplesPerPixel, BitsAllocated, BitsStored, HighBit, PixelRepresentation, PlanarConfiguration.
Use Cases: Medical imaging analysis, radiology research, clinical image processing, multi-frame cine loops.
Enabling:
Dependencies: libdicom, libjpeg or libjpeg-turbo. Optionally, libgdcm-dev (providing gdcmjpeg8/gdcmjpeg12/gdcmjpeg16) enables JPEG Lossless (Process 14) decode; without it, JPEG Lossless files are rejected cleanly with NC_EINVAL.
Supported Transfer Syntaxes:
1.2.840.10008.1.2.4.50), JPEG Lossless (1.2.840.10008.1.2.4.57, 1.2.840.10008.1.2.4.70, requires libgdcm-dev).DICM magic (legacy ACR-NEMA-style files).Resources: libdicom on GitHub · DICOM Standard
Example:
NEP includes Python visualization examples in examples/viz/ that open DICOM files through the NetCDF UDF interface and write publication-ready PNGs.
plot_dicom_mrbrain.py — plots the single-frame 512×512 MR image from test/data/DICOM/MRBRAIN.DCM, normalizing the 16-bit pixel_data to 8-bit grayscale.plot_dicom_xa_montage.py — plots a compact montage of all 17 frames from the encapsulated JPEG Baseline file test/data/DICOM/0003.DCM.plot_dicom_ct_brain.py — plots the single-frame 512×512 CT image from test/data/DICOM/CT-MONO2-16-brain.dcm.Enable the examples with:
Run only the DICOM visualizations with ctest --test-dir build -R viz_dicom --output-on-failure. Generated artifacts are dicom_mrbrain_image.png + _metadata.txt and dicom_xa_frame_montage.png + _metadata.txt in the visualization build directory.
Because DICOM magic is at byte offset 128, netCDF4.Dataset cannot pass the NC_UDF6 mode flag required for direct open. The scripts load libncdicom.so and call NC_DICOM_initialize() via examples/viz/_dicom_udf.py, then read pixel_data through the NetCDF-C UDF API. Make sure LD_LIBRARY_PATH includes the directory containing libncdicom.so (the build systems set this automatically).
DICOM files are read-only and are opened via UDF slot 6 (NC_UDF6).