def color_map(alpha=True, as_int=False, int_type='uint8'): """Generates a color map from color ids to rgb Arguments --------- alpha : bool If True return a color map with alpha values. Returns ------- color_map : array An array of rgb colors for each label. """ cm = annotation.colors_rgb return col.color(cm, alpha=alpha, as_int=as_int, int_type=int_type)
def label_to_color(self, label, key='order', level=None, alpha=True, as_int=False, int_type='uint8'): cm = self.colors_rgb cm = col.color(cm, alpha=alpha, as_int=as_int, int_type=int_type) if key != 'order' or level is not None: label = self.convert_label(label, key=key, value='order', level=level) return cm[label]
def set_background(view, color): """Set the background color of the view. Arguments --------- view : view The vispy window. color : color specification The color for the background. Returns ------- view : view The vispy view of the plot. """ view = get_view(view) view.canvas.bgcolor = col.color(color, alpha=True, as_int=False) return view
def color(self, *args, **kwargs): return col.color(self.data['rgb'], **kwargs)
def _test(): import numpy as np import ClearMap.Tests.Files as tf import ClearMap.Analysis.Graphs.GraphProcessing as gp #reload(gp) skeleton = tf.source('skeleton'); #import ClearMap.Visualization.Plot3d as p3d #p3d.plot(skeleton) #reload(gp) g = gp.graph_from_skeleton(skeleton) g.vertex_coordinates() s = gp.graph_to_skeleton(g) assert np.all(s==skeleton) gc = gp.clean_graph(g, verbose=True) gr = gp.reduce_graph(gc, verbose=True) gr2 = gr.copy(); gr2.set_edge_geometry_type('edge') l = gr.edge_geometry_lengths(); print(l) g = gp.ggt.Graph(n_vertices=10); g.add_edge(np.array([[7,8],[7,9],[1,2],[2,3],[3,1],[1,4],[4,5],[2,6],[6,7]])); g.set_vertex_coordinates(np.array([[10,10,10],[0,0,0],[1,1,1],[1,1,0],[5,0,0],[8,0,1],[0,7,1],[0,10,2],[0,12,3],[3,7,7]], dtype=float)); import ClearMap.Visualization.Plot3d as p3d p3d.plot_graph_line(g) gc = gp.clean_graph(g, verbose=True); p3d.plot_graph_line(gc) gr = gp.reduce_graph(gc, edge_geometry=True, verbose=True) #gr.set_edge_geometry(0.1*np.ones(gr.edge_geometry(as_list=False).shape[0]), 'radii') import ClearMap.Visualization.Plot3d as p3d vertex_colors = np.random.rand(g.n_vertices, 4); vertex_colors[:,3] = 1; p3d.plot_graph_mesh(gr, default_radius=1, vertex_colors=vertex_colors) eg = gr.edge_geometry(as_list=False); egs = 0.5 * eg; gr.set_edge_geometry(name='coordinates', values=egs) #tracing import numpy as np import ClearMap.Visualization.Plot3d as p3d import ClearMap.Analysis.Graphs.GraphProcessing as gp g = gp.ggt.Graph(n_vertices=10); g.add_edge(np.array([[0,1],[1,2],[2,3],[3,4],[4,0],[0,5],[5,6],[6,7],[0,8],[8,9],[9,0]])); g.set_vertex_coordinates(np.array([[0,0,0],[1,0,0],[2,0,0],[2,2,0],[0,1,0],[0,0,1],[0,0,2],[0,0,3],[0,-1,0],[0,-1,-1]], dtype=float)); g.set_vertex_radii(np.array([10,6,4,6,7,4,2,2,5,5]) * 0.02) vertex_colors = np.array([g.vertex_radii()]*4).T; vertex_colors = vertex_colors / vertex_colors.max(); vertex_colors[:,3] = 1; p3d.plot_graph_mesh(g, default_radius=1, vertex_colors=vertex_colors) def condition(graph, vertex): r = graph.vertex_radii(vertex=vertex); print('condition, vertex=%d, radius=%r' % (vertex,r)) return r >= 5 * 0.02; label = np.zeros(g.n_vertices, dtype=bool); label[0] = True; traced = gp.trace_vertex_label(g, label, condition=condition, steps=1) print(traced) vertex_colors = np.array([[1,0,0,1],[1,1,1,1]])[np.asarray(traced, dtype=int)] p3d.plot_graph_mesh(g, default_radius=1, vertex_colors=vertex_colors) from importlib import reload; reload(gp) # edge tracing import ClearMap.Analysis.Graphs.GraphGt as ggt edges = [[0,1],[1,2],[2,3],[4,5],[5,6],[1,7]]; g = ggt.Graph(edges=edges) l,m = g.edge_graph(return_edge_map=True); import numpy as np label = np.zeros(len(edges), dtype=bool); label[1] = True; import ClearMap.Analysis.Graphs.GraphProcessing as gp def condition(graph, edge): print('condition, edge=%d' % (edge,)) return True; traced = gp.trace_edge_label(g, label, condition=condition); print(traced) # expansion of edge lengths import numpy as np import ClearMap.Tests.Files as tf import ClearMap.Analysis.Graphs.GraphProcessing as gp graph = gp.ggt.Graph(n_vertices=5); graph.add_edge([[0,1],[0,2],[0,3],[2,3],[2,1],[0,4]]); graph.add_edge_property('length', np.array([0,1,2,3,4,5])+2); e, m = gp.expand_graph_length(graph, 'length', True) import graph_tool.draw as gd pos = gp.ggt.vertex_property_map_to_python(gd.sfdp_layout(e.base)) import matplotlib.pyplot as plt plt.figure(1); plt.clf(); import matplotlib.collections as mc import ClearMap.Visualization.Color as col colors = np.array([col.color(c) for c in ['red', 'blue', 'green', 'black', 'purple', 'orange']]) ec = e.edge_connectivity(); lines = pos[ec]; cols = colors[m]; lc = mc.LineCollection(lines, linewidths=1, color=cols); ax = plt.gca(); ax.add_collection(lc) ax.autoscale() ax.margins(0.1) plt.scatter(pos[:,0], pos[:,1]) p =pos[:graph.n_vertices] plt.scatter(p[:,0],p[:,1], color='red')