Example #1
0
    def __init__(self, filepath):

        self.lines = load_vtk_streamlines(filepath)

        # these will be from a tangential seed
        self.seedlines = []

        self.lines_crsovr = []
        self.lines_crsovr_fail = []

        # sens spec
        self.sens = []
        self.spec = []
Example #2
0
 def track(self):
     Tracker.track(self)
     self.streamlines = []
     bundle_count = 0
     for file in os.listdir(self.path):
         if file.endswith(".fib"):
             bundle_count = bundle_count + 1
             sl = load_vtk_streamlines(os.path.join(self.path, file))
             self.streamlines.extend(sl)
     if len(self.streamlines) != 200433 or bundle_count != 25:
         raise ISMRMStreamlinesNotCorrectError(self, self.path)
     if self.options.streamline_count is not None:
         self.streamlines = random.sample(self.streamlines, self.options.streamline_count)
Example #3
0
def load_streamlines(path: str, to_lps=True) -> list:
    """
    Loads streamlines from the given path.
    Parameters
    ----------
    path
        The path to load streamlines from
    to_lps
        If True, we load streamlines under the assumption that they were stored in LPS (True by default)
    Returns
    -------
    list
        The streamlines we are trying to load
    """
    if os.path.isdir(path):
        streamlines = []
        for file in os.listdir(path):
            if file.endswith(".fib") or file.endswith(".vtk"):
                sl = load_vtk_streamlines(os.path.join(path, file), to_lps)
                streamlines.extend(sl)
    else:
        streamlines = load_vtk_streamlines(path, to_lps)
    return streamlines
Example #4
0
 def track(self):
     Tracker.track(self)
     self.streamlines = load_vtk_streamlines(self.path)
    #base = "/home/u2hussai/Unfolding/data/diffusionSimulations_res-"
    #npath=base + str(int(res[i] * 1000)) + "um_drt-" + str(int(drt[j] * 100)) + "_angthr-" + str(int(ang_thr[
    # k])) + "/"

    base = "/home/u2hussai/scratch/unfoldingSimulations/diffusionSimulations_scale_50_res-"
    npath = base + str(int(res[i_io] * 1000)) + "um_drt-" + str(int(drt[j_io] * 100)) + "_w-" + \
            str(int(round(w[l_io], 2) * 100)) + "_angthr-" + str(int(ang_thr[k_io])) + "/"

    mask_nii, radtang_nii, halfdrt_nii, angles_nii, updown_nii = loadmasks(
        npath)
    U_nii = load(npath + 'U.nii.gz')
    V_nii = load(npath + 'V.nii.gz')

    print('Loading from' + npath)
    #load native and unfolded strealines
    nlines = lesspoints(load_vtk_streamlines(npath + 'native_streamlines.vtk'))
    ulines = lesspoints(
        load_vtk_streamlines(npath + 'from_unfold_streamlines.vtk'))

    print('Filtering...')
    nlines_tang = nicelines(npath, nlines)
    ulines_tang = nicelines(npath, ulines)
    print(len(nlines))

    print('Getting native voxels')
    # #get the voxel inds
    Nrand = 200
    if len(nlines_tang) > Nrand:
        nlines = select_random_set_of_streamlines(nlines_tang, Nrand)
        ulines = select_random_set_of_streamlines(ulines_tang, Nrand)
    ninds = []
Example #6
0
scale = 100
res = [1.75, 1.5, 1.25, 1.00]  #,0.75]
res = np.asarray(res)
res = scale * res / 100
drt = np.linspace(0.1, 0.25, 5)
w = np.linspace(0.9, 0.99, 4)

for i in range(0, len(res)):
    print(i)
    for j in range(0, len(drt)):
        for k in range(3, len(w)):
            base = "/home/uzair/Datasets/diffusionSimulations/data/diffusionSimulations_res-"
            path = base + str(int(res[i] * 10000)) + "mm_drt-" + str(
                int(drt[j] * 100)) + "+w-" + str(int(w[k] * 100)) + "/"

            nstreamlines = streamline.load_vtk_streamlines(
                path + 'native_streamlines.vtk')
            fustreamlines = streamline.load_vtk_streamlines(
                path + 'from_unfold_streamlines.vtk')
            ustreamlines = streamline.load_vtk_streamlines(
                path + 'Unfolded/unfold_streamlines.vtk')
            U, affine = load_nifti(path + 'U.nii.gz')
            V, affine = load_nifti(path + 'V.nii.gz')
            mask, affine = load_nifti(path + 'nodif_brain_mask.nii.gz')
            one_slice = copy.deepcopy(mask)
            one_slice[:, :, 1:] = 0
            one_slice[np.isnan(one_slice) == 1] = 0
            nstreamlines = Streamlines(target(nstreamlines, affine, one_slice))

nrad, ntang = rad_tang_native(nstreamlines, drt[j], U, affine)
furad, futang = rad_tang_native(fustreamlines, drt[j], U, affine)
Example #7
0
import pyvista as pv
from coordinates import toWorld

#subs_strings = ['sub', 'CA1', 'CA2', 'CA3', 'CA4']
subs_strings = ['CA1CA3e']
s = 0
i = 1

native_streamlines = "native_streamline_%s_bin-%d.vtk" % (subs_strings[s], i)
unfold_streamlines = "unfold_streamlines_%s_bin-%d.vtk" % (subs_strings[s], i)
from_unfold_streamlines = "from_unfold_streamlines_%s_bin-%d.vtk" % (
    subs_strings[s], i)
roi_nii = nib.load('data/oldUnfold/U.nii.gz')
roi = roi_nii.get_fdata()

nlines = load_vtk_streamlines('data/oldUnfold/' + native_streamlines)
ulines = load_vtk_streamlines('data/oldUnfold/' + from_unfold_streamlines)
#unfoldlines=load_vtk_streamlines('data/oldUnfold/Unfolded/'+unfold_streamlines)

surface_opacity = 0.05
surface_color = [0, 1, 1]

roi_actor = actor.contour_from_roi(roi, roi_nii.affine, surface_color,
                                   surface_opacity)


def plot_streamlines(streamlines, roi_actor):
    if has_fury:
        # Prepare the display objects.
        color = colormap.line_colors(streamlines)