questions > DCM2NIIX convert CT scans with localiser -- no output
Showing 1-3 of 3 posts
Display:
Results per page:
Jun 26, 2020  12:06 PM | Wenwen Li - University of Sheffield
DCM2NIIX convert CT scans with localiser -- no output
Hello,

I am converting brain CT scans to NIFTIs. Some of the scans has localiser slices in the DICOM folders.

I used the DCM2NIIX optiion -i y to try to only convert the slices that are not localiser. However, it didn't give me any output. I think the reason is that all the slices in this folder are derived. According to the dcm2niix doc http://manpages.ubuntu.com/manpages/focal/man1/dcm2niix.1.html

-i
Ignore derived, localizer and 2D images.

Since the first slice image type is 'DERIVED\PRIMARY\LOCALIZER\CT_SOM5 SPO' while the rest of the slices are 'DERIVED\PRIMARY\AXIAL\CT_SOM5 SPO', i.e., all the slices are derived, I cannot get any output if I set -i y.

May I ask if there is any other way to convert the scan which has all derived slices, but not convert the locaiser slice to the final NIFTI?

Many thanks,
Wenwen
Jun 26, 2020  03:06 PM | Chris Rorden
RE: DCM2NIIX convert CT scans with localiser -- no output
There are an unlimited number of ways a user might want to cull unwanted images. You can always create your own custom fork of the project and insert your preferred logic. However, my sense is that the easiest solution is to write simple scripts to identify undesired images and remove them. The following script shows how to identify all the 2D NIfTI images in a folder, and can be extended to remove them and their associated files (e.g. .json, .bvec, .bval):

______________________

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# slices.py ~/MyNIFTIs : test NIFTI files in folder 'MyNIFTIs'
# slices.py : test NIFTI files in folder Current Working Directory

import sys
import os
import nibabel as nib
def nii_slices(fnm):
"""
report slices in NIfTI image fnm
Parameters
----------
fnm : str
name of NIfTI image
indir : str
folder with files to compress/decompress
"""
img = nib.load(fnm)
hdr = img.header
dims = hdr.get_data_shape()
if (len(dims) < 3) or ((len(dims) > 2) and (dims[2] < 2) ):
print('2D file: ' + fnm)
return
print('not a 2D file (', dims[2], 'slices, ', len(dims), 'dimensions) :', fnm);
if __name__ == '__main__':
indir = './'
if len(sys.argv) > 1:
indir = sys.argv[1]
if not os.path.isdir(indir):
sys.exit('Unable to find folder ' + indir)
for fnm in os.listdir(indir):
if fnm.endswith('.nii') or fnm.endswith('.nii.gz'):
nii_slices(fnm)
Jun 26, 2020  04:06 PM | Wenwen Li - University of Sheffield
RE: DCM2NIIX convert CT scans with localiser -- no output
Many thanks for the script, Chris!