SimpleITK读取nii图像的头文件
from __future__ import print_function
import SimpleITK as sitk
import sys, os
if len ( sys.argv ) < 2:
print( "Usage: DicomImagePrintTags <input_file>" )
sys.exit ( 1 )
reader = sitk.ImageFileReader()
reader.SetFileName( sys.argv[1] )
reader.LoadPrivateTagsOn();
reader.ReadImageInformation();
for k in reader.GetMetaDataKeys():
v = reader.GetMetaData(k)
print("({0}) = = \"{1}\"".format(k,v))
print("Image Size: {0}".format(reader.GetSize()));
print("Image PixelType: {0}".format(sitk.GetPixelIDValueAsString(reader.GetPixelID())));
nibabel读取nii头文件
def save(filename, obj):
""" Save an nipy image object to a file.
"""
obj = as_volume_img(obj, copy=False)
hdr = nib.Nifti1Header()
for key, value in obj.metadata.iteritems():
if key in hdr:
hdr[key] = value
img = nib.Nifti1Image(obj.get_data(),
obj.affine,
header=hdr)
nib.save(img, filename)