Incomplete acquisition: dicom to nifti

Does anyone have a good way of dealing with incomplete acquisitions (scan stopped before it ended) when converting dicoms to nifti files? The problem is that the volume during which the scan is stopped (Philips) is incomplete which means that the total number of slices is not an integer multiple of the number of slices per volume. When I convert with dcm2niix, I do get a warning, but it also still converts dicoms into a nifti file that cannot be read.

I can of course manually check the slice numbers in the dicom filenames and delete the dicom images from the incomplete volume, but this is a bit involved and I have a feeling that there must be tools out there that can handle this situation more easily. I don’t see an option in dcm2niix that will solve this for me but maybe I’m missing something.

1 Like

I’d suggest opening an issue at the dcm2niix repository. Perhaps there is indeed an easy solution.

In any case, however, distinguish between an incomplete acquisition and a broken acquisition is not really straight forward and would require some sort of heuristics. Deleting the DICOMs (which serve no purpose anyway) is probably the best you could do, also in terms of data archiving.

You can use dcmdump from dcmtk to parse DICOMs really quick. Printing out a specific entry is even faster an can be accomplished with, for example:

# Extract series date from dicom
SERIESDATE="0008,0021"
dcmdump +T +P $SERIESDATE image.dcm | awk '{print $2}'

Thanks for the advice, I’ll look into it. And yes, it’s probably a good idea to ask this directly at dcm2niix as well.

As an example of when I try to convert a folder with such an incomplete set of slices I get the following:

$ dcm2niix -b y -f %p_%s_%t -o ./ ./scan19
Chris Rorden's dcm2niiX version v1.0.20190902 (JP2:OpenJPEG) GCC7.3.0 (64-bit Linux)
Found 6793 DICOM file(s)
Slice positions repeated, but number of slices (6793) not divisible by number of repeats (165): missing images?
Hint: expected 41 locationsWarning: Interslice distance varies in this volume (incompatible with NIfTI format).
Warning: Missing images? Expected 6793 images, but instance number (0020,0013) ranges from 1 to 8565
Warning: Unable to determine slice direction: please check whether slices are flipped Philips Scaling Values RS:RI:SS = 21.7915:0:0.124764 (see PMC3998685) Convert 6793 DICOM as ./task-xxx_run-03_func-bold_1901_20191114094227 (240x240x6793x1)
Compress: "/usr/bin/pigz" -b 960 -n -f -6 "./task-xxx_run-03_func-bold_1901_20191114094227.nii"
Unable to equalize slice distances: slice order not consistently ascending. Recompiling with '-DmyInstanceNumberOrderIsNotSpatial' might help.

With this info I can manually fix it by taking the mod of the number of slices and the number of repeats, then deleting the last n slice dicoms and rerunning dcm2niix. I suppose I could somehow script this procedure.

What would Recompiling with '-DmyInstanceNumberOrderIsNotSpatial' do and how would I do that? Sound like it could be a solution (will also ask @dcm2niix).

I see that I can use dcmdump to extract info from dicoms but I do not quite get how that would help me doing this faster.

I wrote a little python script to do this for me. It’s available here if it’s useful for anyone else: https://github.com/VisionandCognition/NHP-Process-MRI/blob/master/python/fix_dcm_incompletevols.py

It uses the pydicom python package (https://pydicom.github.io/ ) to get the ‘Temporal Position Identifier’ for each dcm file, then identifies the incomplete volume and separates the corresponding dcm files from those belonging to complete volumes.

Running dcm2niix on the cleaned up dataset gives a correct nifti file.

Thanks for pointing me in the right direction!

2 Likes