Пример #1
0
def test_streamline_mapping():
    streamlines = [np.array([[0, 0, 0], [0, 0, 0], [0, 2, 2]], 'float'),
                   np.array([[0, 0, 0], [0, 1, 1], [0, 2, 2]], 'float'),
                   np.array([[0, 2, 2], [0, 1, 1], [0, 0, 0]], 'float')]
    mapping = streamline_mapping(streamlines, (1, 1, 1))
    expected = {(0, 0, 0): [0, 1, 2], (0, 2, 2): [0, 1, 2],
                (0, 1, 1): [1, 2]}
    assert_equal(mapping, expected)

    mapping = streamline_mapping(streamlines, (1, 1, 1),
                                 mapping_as_streamlines=True)
    expected = dict((k, [streamlines[i] for i in indices])
                    for k, indices in expected.items())
    assert_equal(mapping, expected)

    # Test passing affine
    affine = np.eye(4)
    affine[:3, 3] = .5
    mapping = streamline_mapping(streamlines, affine=affine,
                                 mapping_as_streamlines=True)
    assert_equal(mapping, expected)

    # Make the voxel size smaller
    affine = np.diag([.5, .5, .5, 1.])
    affine[:3, 3] = .25
    expected = dict((tuple(i*2 for i in key), value)
                    for key, value in expected.items())
    mapping = streamline_mapping(streamlines, affine=affine,
                                 mapping_as_streamlines=True)
    assert_equal(mapping, expected)
Пример #2
0
def test_streamline_mapping():
    streamlines = [
        np.array([[0, 0, 0], [0, 0, 0], [0, 2, 2]], 'float'),
        np.array([[0, 0, 0], [0, 1, 1], [0, 2, 2]], 'float'),
        np.array([[0, 2, 2], [0, 1, 1], [0, 0, 0]], 'float')
    ]
    mapping = streamline_mapping(streamlines, affine=np.eye(4))
    expected = {(0, 0, 0): [0, 1, 2], (0, 2, 2): [0, 1, 2], (0, 1, 1): [1, 2]}
    npt.assert_equal(mapping, expected)

    mapping = streamline_mapping(streamlines,
                                 affine=np.eye(4),
                                 mapping_as_streamlines=True)
    expected = dict((k, [streamlines[i] for i in indices])
                    for k, indices in expected.items())
    npt.assert_equal(mapping, expected)

    # Test passing affine
    affine = np.eye(4)
    affine[:3, 3] = .5
    mapping = streamline_mapping(streamlines,
                                 affine=affine,
                                 mapping_as_streamlines=True)
    npt.assert_equal(mapping, expected)

    # Make the voxel size smaller
    affine = np.diag([.5, .5, .5, 1.])
    affine[:3, 3] = .25
    expected = dict(
        (tuple(i * 2 for i in key), value) for key, value in expected.items())
    mapping = streamline_mapping(streamlines,
                                 affine=affine,
                                 mapping_as_streamlines=True)
    npt.assert_equal(mapping, expected)
Пример #3
0
def compute_dsc(estimated_tract, true_tract):

    aff=np.array([[-1.25, 0, 0, 90],[0, 1.25, 0, -126],[0, 0, 1.25, -72],[0, 0, 0, 1]])
    voxel_list_estimated_tract = streamline_mapping(estimated_tract, affine=aff).keys()
    voxel_list_true_tract = streamline_mapping(true_tract, affine=aff).keys()
    TP = len(set(voxel_list_estimated_tract).intersection(set(voxel_list_true_tract)))
    vol_A = len(set(voxel_list_estimated_tract))
    vol_B = len(set(voxel_list_true_tract))
    DSC = 2.0 * float(TP) / float(vol_A + vol_B)
    return DSC
def voxelCount():
    tractography, header = trackvis.read(T_A_filename)

    tractography = [streamline[0] for streamline in tractography]

    affine = utils.affine_for_trackvis(voxel_size=np.array([2, 2, 2]))

    print("---Number of voxel---")

    print(len(streamline_mapping(T_A, affine=affine).keys()))
    tkinter.messagebox.showinfo(
        "Voxel", len(streamline_mapping(T_A, affine=affine).keys()))
def dsc(estimated_tract, true_tract):
    """Compute the overlap between the segmented tract and ground truth tract
    """
    aff = np.array([[-1.25, 0, 0, 90], [0, 1.25, 0, -126], [0, 0, 1.25, -72],
                    [0, 0, 0, 1]])
    voxel_list_estimated_tract = streamline_mapping(estimated_tract,
                                                    affine=aff).keys()
    voxel_list_true_tract = streamline_mapping(true_tract, affine=aff).keys()
    TP = len(
        set(voxel_list_estimated_tract).intersection(
            set(voxel_list_true_tract)))
    vol_A = len(set(voxel_list_estimated_tract))
    vol_B = len(set(voxel_list_true_tract))
    DSC = 2.0 * float(TP) / float(vol_A + vol_B)
    return DSC
Пример #6
0
def compute_voxel_measures(estimated_tract, true_tract, aff):

    #aff=np.array([[-1.25, 0, 0, 90],[0, 1.25, 0, -126],[0, 0, 1.25, -72],[0, 0, 0, 1]])
    voxel_list_estimated_tract = streamline_mapping(estimated_tract,
                                                    affine=aff).keys()
    voxel_list_true_tract = streamline_mapping(true_tract, affine=aff).keys()

    n_ET = len(estimated_tract)
    n_TT = len(true_tract)
    dictionary_ET = streamline_mapping(estimated_tract, affine=aff)
    dictionary_TT = streamline_mapping(true_tract, affine=aff)
    voxel_list_intersection = set(voxel_list_estimated_tract).intersection(
        set(voxel_list_true_tract))

    if n_ET == 0:
        return 0, 0, 0, 0, 0, len(set(voxel_list_true_tract))

    sum_int_ET = 0
    sum_int_TT = 0
    for k in voxel_list_intersection:
        sum_int_ET = sum_int_ET + len(dictionary_ET[k])
        sum_int_TT = sum_int_TT + len(dictionary_TT[k])
    sum_int_ET = sum_int_ET / n_ET
    sum_int_TT = sum_int_TT / n_TT

    sum_ET = 0
    for k in voxel_list_estimated_tract:
        sum_ET = sum_ET + len(dictionary_ET[k])
    sum_ET = sum_ET / n_ET

    sum_TT = 0
    for k in voxel_list_true_tract:
        sum_TT = sum_TT + len(dictionary_TT[k])
    sum_TT = sum_TT / n_TT

    TP = len(
        set(voxel_list_estimated_tract).intersection(
            set(voxel_list_true_tract)))
    vol_A = len(set(voxel_list_estimated_tract))
    vol_B = len(set(voxel_list_true_tract))
    FP = vol_B - TP
    FN = vol_A - TP
    sensitivity = float(TP) / float(TP + FN)
    DSC = 2.0 * float(TP) / float(vol_A + vol_B)
    wDSC = float(sum_int_ET + sum_int_TT) / float(sum_ET + sum_TT)
    J = float(TP) / float(TP + FN + FP)

    return DSC, wDSC, J, sensitivity, TP, FP, FN
Пример #7
0
def compute_volume(bundle):
    """Compute voxel volume of a bundle.
	"""
    aff = np.array([[-1.25, 0, 0, 90], [0, 1.25, 0, -126], [0, 0, 1.25, -72],
                    [0, 0, 0, 1]])
    voxel_list = streamline_mapping(bundle, affine=aff).keys()
    vol_bundle = len(set(voxel_list))

    return vol_bundle
Пример #8
0
def compute_X_fa(superset, exID, subjID, nb_points_fa=100):
    """Compute a matrix with dimension (len(superset), nb_points_fa)  
	   that contains the FA profile of the oriented superset.
	"""
    superset = set_number_of_points(superset, nb_points_fa)
    oriented_superset = orient_tract_kmeans(superset)
    X_fa = np.zeros((len(superset), nb_points_fa))
    fa_nii = nib.load('%s/aligned_FA/FA_m%s_s%s.nii.gz' %
                      (subjID, exID, subjID))
    aff = fa_nii.affine
    fa = fa_nii.get_data()
    for s in range(len(oriented_superset) - 1):
        voxel_list = streamline_mapping(oriented_superset[s:s + 1],
                                        affine=aff).keys()
        for v, (i, j, k) in enumerate(voxel_list):
            X_fa[s, v] = fa[i, j, k]
    return X_fa
Пример #9
0
    T_A_filename = 'F:\Thesis\Resources\\alldata\\201111_uf.right.trk'
 
    
    threshold_short_streamlines = 0.0     

    
   
    color=colors.red
    T_A, hdr = loadtrkfile(T_A_filename, threshold_short_streamlines=threshold_short_streamlines) 
    
    countstreamlines()
    showhistogram()
    
    
    

    tractography,header=trackvis.read(T_A_filename)

    tractography = [streamline[0] for streamline in tractography]

    affine=utils.affine_for_trackvis(voxel_size=np.array([2,2,2]))

  

    print ("---Number of voxel---")

    print (len(streamline_mapping(T_A,affine=affine).keys()))
    show_tract(T_A, color)