神经纤维格式转换:tck转trk
场景
MRtrix3
输出的tck神经纤维文件,需要转换成TrackVis
能识别的trk格式
Python实现
#!/usr/bin/env python
import json
import nibabel as nib
from nibabel.streamlines import Field
from nibabel.orientations import aff2axcodes
def main():
tck_file = '/home/amax/data/cye/TractSeg_testcase/KAIPU-mating/dwi_recon_output/fiber_tracts/Fibers/CC.tck'
anatomy_file = '/home/amax/data/cye/TractSeg_testcase/KAIPU-mating/dwi_recon_output/fiber_tracts/bundle_segmentations/CC.nii.gz'
trk_file = '/home/amax/data/cye/TractSeg_testcase/KAIPU-mating/dwi_recon_output/fiber_tracts/Fibers/CC.trk'
nii = nib.load(anatomy_file)
header = {}
header[Field.VOXEL_TO_RASMM] = nii.affine.copy()
header[Field.VOXEL_SIZES] = nii.header.get_zooms()[:3]
header[Field.DIMENSIONS] = nii.shape[:3]
header[Field.VOXEL_ORDER] = "".join(aff2axcodes(nii.affine))
tck = nib.streamlines.load(tck_file)
nib.streamlines.save(tck.tractogram, trk_file, header=header)
if __name__ == '__main__':
main()