rordenlab / dcm2niix

dcm2nii DICOM to NIfTI converter: compiled versions available from NITRC
https://www.nitrc.org/plugins/mwiki/index.php/dcm2nii:MainPage
Other
895 stars 228 forks source link

Siemens XA60 conversion of diffusion data #819

Closed jonbpanda closed 1 month ago

jonbpanda commented 6 months ago

Describe the bug

Not sure this is a bug! Acquired multi-shell diffusion data according to the HCP-D/A protocol (https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6484842/)

Note that the data were acquired with the Siemens product multi-band sequence (not the CMRR version), so every slice for each direction/b-value combination is saved as a separate image (rather than mosaic'ed). There were 92 slices per volume, which relates to the Warning below

However, dcm2niix took absolutely ages (>1 hour) to parse the DICOM folder on a relatively speedy machine.

To reproduce

Steps to reproduce the behavior:

  1. Download the DICOM data (will send via separate email)
  2. Convert using command: dcm2niix -f series%s_%p -z y -o ./Converted ./DICOM
  3. See slow behaviour
  4. 1000s of warnings (as described on neurostars): E.g. Warning: Series 30074 includes partial volume (issue 742): 1 slices acquired but ICE dims {0021, 118e} specifies 92

Expected behavior

Would like to think that dcm2niix could resolve this problem of non-mosaic'ed data and reconstitute the desired volumes - even better if it could munge it into a 4D file and generate the associated bvec and bval files.

Output log

N/A

Version

Please report the complete version string:

dcm2niiX version v1.0.20240202 GCC12.3.0 x86-64 (64-bit Linux)

Troubleshooting

Please try the following steps to resolve your issue:

Latest stable release AFAIK

git clone --branch development https://github.com/rordenlab/dcm2niix.git
cd dcm2niix/console
make
./dcm2niix ....

Haven't had a chance to try this yet. Will try when I have a moment.

mharms commented 6 months ago

FYI: If you export as "Enhanced" DICOM from XA, you'll get 1 DICOM per frame/volume, which is much easier to work with.

neurolabusc commented 3 months ago

@jonbpanda this sounds like the expected behavior. Saving multi-band EPI data as one classic DICOM per slice is extremely inefficient for any tool and storage device. As @mharms notes, you really want to save the data as enhanced DICOM, which for Siemens will save each 3D volume as a separate file. One inherent limitation of the classic DICOM standard is that each slice is saved as a separate file and no file reveals the total number of files in a series. Therefore, one must exhaustively examine each and every slice to work out which series it belongs to.

For sessions that are saved with lots of series in a single session, you can dramatically accelerate dcm2niix by converting in two passes: first rename the DICOMs so that all the images from a single series is saved in a single folder, and that data from each series is saved in a separate folder from each other. Then process each one of the series folders independently. The dcm2niix rename (-r y) function is ideal for the first step.

ChatGPT can help you create a Python or bash script for this. Here is a simple bash script that assumes an existing input folder with DICOMs (~/indir), a non-existent temporary folder to store the renamed DICOMs (~/temp) and an output folder for the NIfTI images (~/outdir). You would call it like this:

./dcm.sh ~/indir ~/temp ~/out

and here is the script:

#!/bin/bash

# Check if the correct number of arguments is provided
if [ "$#" -ne 3 ]; then
  echo "Usage: $0 <indir> <tempdir> <outdir>"
  exit 1
fi

indir="$1"
tempdir="$2"
outdir="$3"

# 1. Terminate if a directory indir does not exist
if [ ! -d "$indir" ]; then
  echo "Error: Input directory '$indir' does not exist."
  exit 1
fi

# 2. Terminate if the directory tempdir does exist
if [ -d "$tempdir" ]; then
  echo "Error: Temporary directory '$tempdir' already exists."
  exit 1
fi

# 3. Create tempdir
mkdir "$tempdir"
if [ $? -ne 0 ]; then
  echo "Error: Failed to create temporary directory '$tempdir'."
  exit 1
fi

# 4. Run dcm2niix with the rename (-r y) argument, using a filename specifier that sorts by series (-f %s..)
dcm2niix -r y -f "%s_%p/%4r_%o.dcm" -o "$tempdir" "$indir"
if [ $? -ne 0 ]; then
  echo "Error: dcm2niix failed to process '$indir'."
  exit 1
fi

# 5. Run dcm2niix sequentially for each folder inside tempdir saving all results to outdir
for dir in "$tempdir"/*; do
  if [ -d "$dir" ]; then
    dcm2niix -o "$outdir" "$dir"
    if [ $? -ne 0 ]; then
      echo "Error: dcm2niix failed to process '$dir'."
      exit 1
    fi
  fi
done

# 6. Delete tempdir and all its contents
rm -rf "$tempdir"
if [ $? -ne 0 ]; then
  echo "Error: Failed to delete temporary directory '$tempdir'."
  exit 1
fi

echo "Processing completed successfully."

If you still think that dcm2niix is slower than one could reasonably expect, share a dataset with my institutional email and I will see if there are any other tricks.

neurolabusc commented 1 month ago

Closing as unable to replicate.