Giter VIP home page Giter VIP logo

Comments (2)

mharms avatar mharms commented on September 22, 2024

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

from dcm2niix.

neurolabusc avatar neurolabusc commented on September 22, 2024

@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.

from dcm2niix.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.