美文网首页
读取nii图像头文件

读取nii图像头文件

作者: snowpigppp | 来源:发表于2019-08-08 14:57 被阅读0次

    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)
    

    相关文章

      网友评论

          本文标题:读取nii图像头文件

          本文链接:https://www.haomeiwen.com/subject/xeexjctx.html