NII文件和nrrd文件的随意转换
Posted Mario cai
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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)
以上是关于NII文件和nrrd文件的随意转换的主要内容,如果未能解决你的问题,请参考以下文章