questions > RE: DCM2NIIX convert CT scans with localiser -- no output
Jun 26, 2020  08:06 AM | 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)

Threaded View

TitleAuthorDate
Wenwen Li Jun 26, 2020
RE: DCM2NIIX convert CT scans with localiser -- no output
Chris Rorden Jun 26, 2020
Wenwen Li Jun 26, 2020