def get_tracts(tracts_folder):
    """Loads tracts in an atlas folder and converts them from .nii.gz format to numpy ndarray 
    Save path of each tracts
    Only the tract must be in tracts_format in the folder"""
    fname_tract = glob.glob(tracts_folder + '/*' + '.nii.gz')
    
    #Initialise tracts variable as object because there are 4 dimensions
    tracts = np.empty([len(fname_tract), 1], dtype=object)
    
    #Load each partial volumes of each tracts
    for label in range(0, len(fname_tract)):
       tracts[label, 0] = nib.load(fname_tract[label]).get_data()
    
    #Reshape tracts if it is the 2D image instead of 3D
    for label in range(0, len(fname_tract)):
       if (tracts[label,0]).ndim == 2:
           tracts[label,0] = tracts[label,0].reshape(int(np.size(tracts[label,0],0)), int(np.size(tracts[label,0],1)),1)
    return tracts
dataset/ETHPy150Open neuropoly/spinalcordtoolbox/dev/atlas/create_atlas/create_masks_csf_and_gm.py/get_tracts/original