def test_points(interactive=False): points = np.array([[0, 0, 0], [0, 1, 0], [1, 0, 0]]) colors = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) points_actor = actor.point(points, colors) renderer = window.Renderer() renderer.add(points_actor) renderer.reset_camera() renderer.reset_clipping_range() if interactive: window.show(renderer, reset_camera=False) npt.assert_equal(renderer.GetActors().GetNumberOfItems(), 1) arr = window.snapshot(renderer) report = window.analyze_snapshot(arr, colors=colors) npt.assert_equal(report.objects, 3)
# Extract feature of every streamline. centers = np.asarray(list(map(feature.extract, streamlines))) # Color each center of mass according to the cluster they belong to. colormap = colormap.create_colormap(np.arange(len(clusters))) colormap_full = np.ones((len(streamlines), 3)) for cluster, color in zip(clusters, colormap): colormap_full[cluster.indices] = color # Visualization scene = window.Scene() scene.clear() scene.SetBackground(0, 0, 0) scene.add(actor.streamtube(streamlines, window.colors.white, opacity=0.05)) scene.add(actor.point(centers[:, 0, :], colormap_full, point_radius=0.2)) window.record(scene, n_frames=1, out_path='center_of_mass_feature.png', size=(600, 600)) if interactive: window.show(scene) """ .. figure:: center_of_mass_feature.png :align: center Showing the center of mass of each streamline and colored according to the QuickBundles results. .. _clustering-examples-MidpointFeature:
phi = test[:, 2] # Gradient Table formation for the heck of it gtab_b3000 = gradient_table(b3000_bvals, b3000_bvecs) # Generate a Hemisphere figure plot hsph_initial = HemiSphere(theta=theta, phi=phi) # Enables/disables interactive visualization interactive = True ren = window.Renderer() ren.SetBackground(1, 1, 1) ren.add( actor.point(hsph_initial.vertices, window.colors.red, point_radius=0.05)) if interactive: window.show(ren) print('The Points should be looking good visually !') print('Lets form the much needed sphere') sphere_grad = Sphere(xyz=np.vstack((hsph_initial.vertices, -hsph_initial.vertices))) window.rm_all(ren) ren.add( actor.point(sphere_grad.vertices, actor.colors.green, point_radius=0.05)) if interactive:
hsph_updated, potential = disperse_charges(hsph_initial, 5000) """ In ``hsph_updated`` we have the updated ``HemiSphere`` with the points nicely distributed on the hemisphere. Let's visualize them. """ from dipy.viz import window, actor # Enables/disables interactive visualization interactive = False ren = window.Renderer() ren.SetBackground(1, 1, 1) ren.add( actor.point(hsph_initial.vertices, window.colors.red, point_radius=0.05)) ren.add( actor.point(hsph_updated.vertices, window.colors.green, point_radius=0.05)) print('Saving illustration as initial_vs_updated.png') window.record(ren, out_path='initial_vs_updated.png', size=(300, 300)) if interactive: window.show(ren) """ .. figure:: initial_vs_updated.png :align: center Example of electrostatic repulsion of red points which become green points. We can also create a sphere from the hemisphere and show it in the following way. """
# Extract feature of every streamline. centers = np.asarray(list(map(feature.extract, streamlines))) # Color each center of mass according to the cluster they belong to. colormap = actor.create_colormap(np.arange(len(clusters))) colormap_full = np.ones((len(streamlines), 3)) for cluster, color in zip(clusters, colormap): colormap_full[cluster.indices] = color # Visualization ren = window.Renderer() window.clear(ren) ren.SetBackground(0, 0, 0) ren.add(actor.streamtube(streamlines, window.colors.white, opacity=0.05)) ren.add(actor.point(centers[:, 0, :], colormap_full, point_radius=0.2)) window.record(ren, n_frames=1, out_path='center_of_mass_feature.png', size=(600, 600)) if interactive: window.show(ren) """ .. figure:: center_of_mass_feature.png :align: center Showing the center of mass of each streamline and colored according to the QuickBundles results. .. _clustering-examples-MidpointFeature: Midpoint Feature ================
import numpy as np from dipy.core.sphere import disperse_charges, Sphere, HemiSphere from dipy.viz import window, actor n_pts = 64 theta = np.pi * np.random.rand(n_pts) phi = 2 * np.pi * np.random.rand(n_pts) hsph_initial = HemiSphere(theta=theta, phi=phi) hsph_updated, potential = disperse_charges(hsph_initial, 5000) # Enables/disables interactive visualization interactive = True ren = window.Renderer() ren.SetBackground(1, 1, 1) ren.add( actor.point(hsph_initial.vertices, window.colors.red, point_radius=0.05)) ren.add( actor.point(hsph_updated.vertices, window.colors.green, point_radius=0.05)) print('Saving illustration as initial_vs_updated.png') window.record(ren, out_path='initial_vs_updated.png', size=(300, 300)) if interactive: window.show(ren)
# print grad3.shape # vertices = grad3*gradients vertices = gradients if omit > 0: vertices = vertices[omit:, :] if entry['hemi']: vertices = np.vstack([vertices, -vertices]) return vertices[omit:, :] print(sphere_dic.keys()) # vertices = get_vertex_set('create5') # vertices = get_vertex_set('siem64') # vertices = get_vertex_set('dsi102') vertices = get_vertex_set('fy362') gradients = get_vertex_set('siem64') gradients = gradients[:gradients.shape[0] / 2] print(gradients.shape) from dipy.viz import window, actor sph = -np.sinc(np.dot(gradients[1], vertices.T)) ren = window.Renderer() # sph = np.arange(vertices.shape[0]) print(sph.shape) cols = window.colors(sph, 'jet') ren.add(actor.point(vertices, cols, point_radius=.1, theta=10, phi=10)) window.show(ren)
def show_seeds(seeds): renderer = window.Renderer() points = actor.point(seeds, colors=np.random.rand(*seeds.shape)) renderer.add(points) window.show(renderer)
bvec_path = r'D:\Users\Vishwesh\PycharmProjects\shore_mapmri\ms_bvecs_b0.bvec' bval_path = r'D:\Users\Vishwesh\PycharmProjects\shore_mapmri\ms_bvals_b0.bval' bvals, bvecs = read_bvals_bvecs(bval_path, bvec_path) print("Debug Here") # Calculate Spherical Coordinates b3000_bvecs = bvecs[0:100,:] test = cart2sphA(b3000_bvecs) theta = test[:,1] phi = test[:,2] # Generate a Hemisphere figure plot hsph_initial = HemiSphere(theta=theta, phi=phi) # Enables/disables interactive visualization interactive = True ren = window.Renderer() ren.SetBackground(1, 1, 1) ren.add(actor.point(hsph_initial.vertices, window.colors.red, point_radius=0.05)) if interactive: window.show(ren)
hsph_updated, potential = disperse_charges(hsph_initial, 5000) """ In ``hsph_updated`` we have the updated ``HemiSphere`` with the points nicely distributed on the hemisphere. Let's visualize them. """ from dipy.viz import window, actor # Enables/disables interactive visualization interactive = False ren = window.Renderer() ren.SetBackground(1, 1, 1) ren.add(actor.point(hsph_initial.vertices, window.colors.red, point_radius=0.05)) ren.add(actor.point(hsph_updated.vertices, window.colors.green, point_radius=0.05)) print('Saving illustration as initial_vs_updated.png') window.record(ren, out_path='initial_vs_updated.png', size=(300, 300)) if interactive: window.show(ren) """ .. figure:: initial_vs_updated.png :align: center Example of electrostatic repulsion of red points which become green points. We can also create a sphere from the hemisphere and show it in the following way. """