神经纤维格式转换:tck转trk

Fiber tracks

场景

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()
Chenfei Ye
Chenfei Ye
A connectome weaver

The brain’s billions of neurons resemble trees of many species and come in many fantastic shapes. Only the most determined explorers can hope to capture a glimpse of this forest’s interior, and even they see little, and see it poorly.