dcmstack

raw JSON →
0.9.0 verified Sat May 09 auth: no python maintenance

dcmstack is a Python library (currently v0.9.0, last released stable) that stacks DICOM images into 3D volumes and converts them to NIfTI format. It has a very slow release cadence (last release in 2015) and supports Python >=2.7. The project is effectively in maintenance mode.

pip install dcmstack
error ModuleNotFoundError: No module named 'dcmstack'
cause dcmstack is not installed or installed in the wrong Python environment.
fix
Run: pip install dcmstack
error AttributeError: 'DicomStack' object has no attribute 'add_file'
cause Using an outdated version (<0.8.0) where the API was different.
fix
Upgrade to version 0.9.0: pip install dcmstack==0.9.0
deprecated dcmstack is no longer actively maintained. The last release was in 2015, and it only supports Python 2.7 officially. Consider using dcm2niix or Dicom2Nifti for modern projects.
fix Migrate to dcm2niix (command-line) or the Python library dicom2nifti.
gotcha The library does not handle gzipped NIfTI output directly; you must use nibabel to save as .nii.gz.
fix After calling stack.to_nifti(), save the resulting nibabel image using nib.save(img, 'output.nii.gz').

Basic usage: add DICOM files to a DicomStack and convert to NIfTI.

import dcmstack
from glob import glob

# Stack a series of DICOM files into a NIfTI file
file_list = sorted(glob('path/to/dicom/*.dcm'))
stack = dcmstack.DicomStack()
for f in file_list:
    stack.add_file(f)
nifti_img = stack.to_nifti()
nib.save(nifti_img, 'output.nii.gz')