예제 #1
0
 def run(self, ips, snap, img, para = None):
     g = ips.data
     for n in list(g.nodes()):
         if len(g[n])==0: g.remove_node(n)
     img *= 0
     sknw.draw_graph(img, g)
     ips.mark = Mark(ips.data)
예제 #2
0
 def run(self, ips, imgs, para = None):
     nodes = nx.shortest_path(ips.data, source=para['start'], target=para['end'], weight='weight')
     path = zip(nodes[:-1], nodes[1:])
     paths = []
     for s,e in path:
         ps = ips.data[s][e].values()
         pts = sorted([(i['weight'], i['pts']) for i in ps])
         paths.append(((s,e), pts[0]))
     sknw.draw_graph(ips.img, ips.data)
     for i in paths:
         ips.img[i[1][1][:,0], i[1][1][:,1]] = 255
         IPy.write('%s-%s:%.4f'%(i[0][0], i[0][1], i[1][0]), 'ShortestPath')
     IPy.write('Nodes:%s, Length:%.4f'%(len(nodes), sum([i[1][0] for i in paths])), 'ShortestPath')
예제 #3
0
 def run(self, ips, imgs, para=None):
     g = ips.data
     k, unit = ips.unit
     while True:
         rm = []
         for i in g.nodes():
             if g.degree(i) != 1: continue
             s, e = list(g.edges(i))[0]
             if g[s][e][0]['weight'] * k <= para['lim']:
                 rm.append(i)
         g.remove_nodes_from(rm)
         if not para['rec'] or len(rm) == 0: break
     imgs *= 0
     sknw.draw_graph(imgs, g)
예제 #4
0
    def run(self, ips, imgs, para = None):
        nodes = nx.shortest_path(ips.data, source=para['start'], target=para['end'], weight='weight')
        path = zip(nodes[:-1], nodes[1:])
        paths = []
        for s,e in path:
            ps = ips.data[s][e].values()
            pts = sorted([(i['weight'], i['pts']) for i in ps])
            paths.append(((s,e), pts[0]))
        sknw.draw_graph(ips.img, ips.data)

        for i in paths:
            ips.img[i[1][1][:,0], i[1][1][:,1]] = 255

        data = [(a[0], a[1], b[0]) for a,b in paths]
        self.app.show_table(pd.DataFrame(data, columns=['from','to','l']), 'shortest-path')
예제 #5
0
 def run(self, ips, imgs, para=None):
     g = ips.data
     for n in list(g.nodes()):
         if len(g[n]) != 2 or n in g[n]: continue
         (k1, e1), (k2, e2) = g[n].items()
         if isinstance(g, nx.MultiGraph):
             if len(e1) != 1 or len(e2) != 1: continue
             e1, e2 = e1[0], e2[0]
         l1, l2 = e1['pts'], e2['pts']
         d1 = norm(l1[0] - g.node[n]['o']) > norm(l1[-1] - g.node[n]['o'])
         d2 = norm(l2[0] - g.node[n]['o']) < norm(l2[-1] - g.node[n]['o'])
         pts = np.vstack((l1[::[-1, 1][d1]], l2[::[-1, 1][d2]]))
         l = np.linalg.norm(pts[1:] - pts[:-1], axis=1).sum()
         g.remove_node(n)
         g.add_edge(k1, k2, pts=pts, weight=l)
     imgs *= 0
     sknw.draw_graph(imgs, g)
예제 #6
0
 def run(self, ips, imgs, para=None):
     g = ips.data
     for n in list(g.nodes()):
         if len(g[n]) == 0: g.remove_node(n)
     imgs *= 0
     sknw.draw_graph(imgs, g)
예제 #7
0
 def run(self, ips, imgs, para=None):
     ips.data = sknw.build_sknw(imgs, True)
     sknw.draw_graph(imgs, ips.data)
예제 #8
0
 def run(self, ips, snap, img, para = None):
     ips.data = sknw.build_sknw(img, True)
     sknw.draw_graph(img, ips.data)
     ips.mark = Mark(ips.data)