其他分享
首页 > 其他分享> > NII文件和nrrd文件的随意转换

NII文件和nrrd文件的随意转换

作者:互联网

import os
from glob import glob
import numpy as np
import vtk


def readnrrd(filename):
    """Read image in nrrd format."""
    reader = vtk.vtkNrrdReader()
    reader.SetFileName(filename)
    reader.Update()
    info = reader.GetInformation()
    return reader.GetOutput(), info


def writenifti(image,filename, info):
    """Write nifti file."""
    writer = vtk.vtkNIFTIImageWriter()
    writer.SetInputData(image)
    writer.SetFileName(filename)
    writer.SetInformation(info)
    writer.Write()


if __name__ == '__main__':
    baseDir = os.path.normpath(r'C:\Users\Admin\Desktop\EGFR total\EGFRzhong\EGFRzhong\data\0')
    files = glob(baseDir+'/*.nrrd')
    for file in files:
        m, info = readnrrd(file)
        writenifti(m,  file.replace( '.nrrd','.nii.gz'), info)

标签:info,文件,NII,file,writer,nrrd,filename,__,reader
来源: https://blog.csdn.net/caihaihua0572/article/details/123031460