Created
May 31, 2017 18:07
-
-
Save samuelstjean/27a63ba2cf1f94a7a284e145829b0bc3 to your computer and use it in GitHub Desktop.
Remove the comments field from a nifti file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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