Skip to content

Instantly share code, notes, and snippets.

@samuelstjean
Created May 31, 2017 18:07
Show Gist options
  • Save samuelstjean/27a63ba2cf1f94a7a284e145829b0bc3 to your computer and use it in GitHub Desktop.
Save samuelstjean/27a63ba2cf1f94a7a284e145829b0bc3 to your computer and use it in GitHub Desktop.
Remove the comments field from a nifti file
#! /usr/bin/env python
import nibabel as nib
import sys
if len(sys.argv) <= 2:
print('Usage : strip_comments_from_nifti.py input_file output_file')
exit()
infile, outfile = sys.argv[1:]
vol = nib.load(infile)
data = vol.get_data()
affine = vol.get_affine()
header = vol.get_header()
# Strip comments field, passes the fslhd, print header from nibabel
# and mrinfo tests for comments string.
header['db_name'] = ''
header['descrip'] = ''
# Save back everything
nib.save(nib.Nifti1Image(data, affine, header), outfile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment