Пример #1
0
def _test():
  """Tests."""
  import numpy as np
  import ClearMap.Visualization.Plot3d as p3d
  import ClearMap.Tests.Files as tsf
  import ClearMap.ImageProcessing.Experts.Vasculature as vasc
  
  source = np.array(tsf.source('vls')[:300,:300,80:120]);
  source[:,:,[0,-1]] = 0;
  source[:,[0,-1],:] = 0;
  source[[0,-1],:,:] = 0;
    
  bpar = vasc.default_binarization_parameter.copy();
  bpar['clip']['clip_range'] = (150, 7000)
  bpar['as_memory'] = True
  #bpar['binary_status'] = 'binary_status.npy'
  
  ppar = vasc.default_processing_parameter.copy();
  ppar['processes'] = 10;
  ppar['size_max'] = 10;
  
  sink='binary.npy'
  #sink=None;
  
  binary = vasc.binarize(source, sink=sink, binarization_parameter=bpar, processing_parameter = ppar) 
  p3d.plot([source, binary])

  import ClearMap.IO.IO as io
  io.delete_file(sink)
  
  pppar = vasc.default_postprocessing_parameter.copy();
  pppar['smooth']['iterations'] = 3;
  smoothed = vasc.postprocess(binary, postprocessing_parameter=pppar)
  p3d.plot([binary, smoothed])
Пример #2
0
def _test():
    """Tests"""
    import ClearMap.Tests.Files as tsf
    import ClearMap.Visualization.Plot3d as p3d

    import ClearMap.ImageProcessing.LightsheetCorrection as ls
    from importlib import reload
    reload(ls)

    s = tsf.source('vasculature_lightsheet_raw')
    #p3d.plot(s)

    import ClearMap.ImageProcessing.Experts.Vasculature as vasc
    clipped, mask, high, low = vasc.clip(s[:, :, 80:120],
                                         clip_range=(400, 60000))

    corrected = ls.correct_lightsheet(clipped,
                                      mask=mask,
                                      percentile=0.25,
                                      lightsheet=dict(selem=(150, 1, 1)),
                                      background=dict(selem=(200, 200, 1),
                                                      spacing=(25, 25, 1),
                                                      step=(2, 2, 1),
                                                      interpolate=1),
                                      lightsheet_vs_background=2)

    p3d.plot([clipped, corrected])
Пример #3
0
def _test():
    import ClearMap.Tests.Files as tfs
    import ClearMap.IO.TIF as tif
    reload(tif)

    filename = tfs.filename('tif_2d')
    t = tif.Source(location=filename)
    print(t)

    filename = tfs.filename('tif_2d_color')
    t = tif.Source(location=filename)
    print(t)

    d = tif.read(filename)
    print(d.shape)

    v = t.as_virtual()
    print(v)

    q = v.as_real()
    print(q)
Пример #4
0
def _test():
    import numpy as np
    import ClearMap.ImageProcessing.Filter.Rank.Rank as rnk
    reload(rnk)

    import ClearMap.Tests.Files as tfs
    data = np.asarray(tfs.source('vr')[:100, :100, 50], dtype=float)
    data = np.asarray(255 * data / data.max(), dtype='uint8')

    funcs = rnk.__all__[:-1]
    n = len(funcs)
    m = int(np.ceil(np.sqrt(n)))
    p = int(np.ceil(float(n) / m))

    import matplotlib.pyplot as plt
    plt.figure(1)
    plt.clf()
    ax = plt.subplot(m, p, 1)
    plt.imshow(data)
    plt.title('original')

    for i, f in enumerate(funcs):
        func = eval('rnk.' + f)
        res = func(data, selem=np.ones((5, 5, 5), dtype=bool))

        plt.subplot(m, p, i + 2, sharex=ax, sharey=ax)
        plt.imshow(res)
        plt.title(f)

    plt.tight_layout()

    #masked version
    mask = np.zeros(data.shape, dtype=bool)
    mask[30:60, 30:60] = True

    import matplotlib.pyplot as plt
    plt.figure(2)
    plt.clf()
    ax = plt.subplot(m, p, 1)
    plt.imshow(data)
    plt.title('original')

    for i, f in enumerate(funcs):
        func = eval('rnk.' + f)
        res = func(data, selem=np.ones((5, 5), dtype=bool), mask=mask)

        plt.subplot(m, p, i + 2, sharex=ax, sharey=ax)
        plt.imshow(res)
        plt.title(f)

    plt.tight_layout()
Пример #5
0
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.has_edge_geometry()

    g.vertex_coordinates()

    s = g.skeleton()
    assert np.all(s == skeleton)

    gc = gp.clean_graph(g, verbose=True)

    gr = gp.reduce_graph(gc, verbose=True)

    coordinates, indices = gr.edge_geometry(return_indices=True, as_list=False)

    gr.set_edge_geometry(name='radii', values=np.ones(len(coordinates)))

    radii = gr.edge_geometry('radii', as_list=False)

    import ClearMap.Analysis.Graphs.GraphVisualization as gv
    reload(gv)

    grid, grid_indices = gv.mesh_from_edge_geometry(coordinates=coordinates,
                                                    radii=radii,
                                                    indices=indices)

    import ClearMap.Visualization.GraphVisual as gvi

    gvi.plot_mesh(grid, grid_indices)
Пример #6
0
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')