读取nii图像头文件

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)
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容