Skip to content

Instantly share code, notes, and snippets.

@schluppeck
Last active July 24, 2023 17:43
Show Gist options
  • Select an option

  • Save schluppeck/06c965ebbe8cd7700b8f94e21a7ddddc to your computer and use it in GitHub Desktop.

Select an option

Save schluppeck/06c965ebbe8cd7700b8f94e21a7ddddc to your computer and use it in GitHub Desktop.
converting DCM to nifti

Conversion notes

Denis Schluppeck, 2023-07-21

Converting GE data via XNAT at SPMIC/Psychology. Trying to find a consistent workflow for Psychology users, especially for fMRI and related.

things to consider

  • voxel sizes 2mm isotropic to 2.5mm or even 3mm? SNR gains, data size
  • dummies. GE protocol includes data even before steady-state is reached. Therefore need to cut this by hand? Principled way of doing this in pre-processing in mrTools?
  • standard conversion flags for xnat exported data? Do this as a plugin in xnat itself to avoid local install issues?
  • MB=3, ARC=3 looks like it's too much

Data from GE via XNAT

"%n_%s_%t_%d" which combines patient name field, series name, timestamp and sequence description into filename... e.g.

# converting GE data obtained via XNAT into a reasonable filename ...
# ds 2023-07-20

# create folder to keep all nifti files

function convertImages() {
outputfolder=nifti
mkdir ${outputfolder}

# dcm2niix on each folder
# the piping into sort makes them numeric sorted not text
# outer parens makes it an array!
folders=($(ls -d [0-9]* | sort -n)) 

# or if you want numerical order de novo
# folders=$(seq 2 13)

# make this a variable, so we can futz with it
fnameflags="%n_%s_%t_%d"

for folder in ${folders[@]}; do
    outputfolder=nifti
    echo "converting $folder and storing in ${outputfolder}"
    echo "dcm2niix ${fnameflags} -o ${outputfolder} ${folder}"  
    dcm2niix -f ${fnameflags} -o ${outputfolder} ${folder}
done

}

which gives filenames like:

PO2_2_20230720102203_3D_SAG_T1_MP-RAGE_TI800.json
PO2_2_20230720102203_3D_SAG_T1_MP-RAGE_TI800.nii
PO2_3_20230720102203_t2_flair_sag_p2_1mm_FS.json
PO2_3_20230720102203_t2_flair_sag_p2_1mm_FS.nii
PO2_4_20230720102203_fmri_MB3_ARC2_fMRI_2mm.json
PO2_4_20230720102203_fmri_MB3_ARC2_fMRI_2mm.nii
PO2_5_20230720102203_fmri_MB3_ARC2_fMRI_2mm.json
PO2_5_20230720102203_fmri_MB3_ARC2_fMRI_2mm.nii
PO2_6_20230720102203_fmri_MB3_ARC2_fMRI_2mm.json
...

from the dcm2niix documentation, checking out flags, espeically -f : filename

field meaning
%a antenna (coil) name
%b basename
%c comments
%d description
%e echo number
%f folder name
%g accession number
%i ID of patient
%j seriesInstanceUID
%k studyInstanceUID
%m manufacturer
%n name of patient
%o mediaObjectInstanceUID
%p protocol
%r instance number
%s series number
%t time
%u acquisition number
%v vendor
%x study ID
%z sequence name

default '%f_%p_%t_%s'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment