本文整理汇总了Python中graph_tool.Graph.edge_properties["w"]方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.edge_properties["w"]方法的具体用法?Python Graph.edge_properties["w"]怎么用?Python Graph.edge_properties["w"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graph_tool.Graph
的用法示例。
在下文中一共展示了Graph.edge_properties["w"]方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: makeGraph
# 需要导入模块: from graph_tool import Graph [as 别名]
# 或者: from graph_tool.Graph import edge_properties["w"] [as 别名]
#.........这里部分代码省略.........
percent=(float(cccc)/float(ss[1]))*100
if percentOld+10< percent:
print str(np.round(percent,1))+'%'
percentOld=percent
nodeNumber1 = (float(i)*yScale,float(j)*xScale)
if gu.find_vertex(G, vprop, {'imgIdx':(j,i),'coord':nodeNumber1, 'nrOfPaths':0, 'diameter':float(dia[j][i])*avgScale}):
v1=gu.find_vertex(G, vprop, {'imgIdx':(j,i),'coord':nodeNumber1, 'nrOfPaths':0, 'diameter':float(dia[j][i])*avgScale})[0]
else:
v1=G.add_vertex()
vprop[G.vertex(v1)]={'imgIdx':(j,i),'coord':nodeNumber1, 'nrOfPaths':0, 'diameter':float(dia[j][i])*avgScale}
try:
if img[j,i+1] == True:
nodeNumber2 = (float(i+1)*yScale,float(j)*xScale)
if gu.find_vertex(G, vprop, {'imgIdx':(j,i+1),'coord':nodeNumber2, 'nrOfPaths':0, 'diameter':float(dia[j][i+1])*avgScale}):
v2=gu.find_vertex(G, vprop, {'imgIdx':(j,i+1),'coord':nodeNumber2, 'nrOfPaths':0, 'diameter':float(dia[j][i+1])*avgScale})[0]
if gu.find_edge(G, eprop, {'coord1':vprop[v2]['coord'], 'coord2':vprop[v1]['coord'],'weight':((vprop[v1]['diameter']+vprop[v2]['diameter'])/2)**4,'RTP':False}):
pass
else:
e = G.add_edge(v1, v2)
epropW[e]=(((vprop[v1]['diameter']+vprop[v2]['diameter'])/2)/avgScale)**4
eprop[e]={'coord1':vprop[v1]['coord'], 'coord2':vprop[v2]['coord'],'weight':((vprop[v1]['diameter']+vprop[v2]['diameter'])/2)**4,'RTP':False}
else:
v2=G.add_vertex()
vprop[G.vertex(v2)]={'imgIdx':(j,i+1),'coord':nodeNumber2, 'nrOfPaths':0, 'diameter':float(dia[j][i+1])*avgScale}
e = G.add_edge(v1, v2)
epropW[e]=(((vprop[v1]['diameter']+vprop[v2]['diameter'])/2)/avgScale)**4
eprop[e]={'coord1':vprop[v1]['coord'], 'coord2':vprop[v2]['coord'],'weight':((vprop[v1]['diameter']+vprop[v2]['diameter'])/2)**4,'RTP':False}
except:
pass
try:
if img[j,i-1] == True:
nodeNumber2 = (float(i-1)*yScale,float(j)*xScale)
if gu.find_vertex(G, vprop, {'imgIdx':(j,i-1),'coord':nodeNumber2, 'nrOfPaths':0, 'diameter':float(dia[j][i-1])*avgScale}):
v2=gu.find_vertex(G, vprop, {'imgIdx':(j,i-1),'coord':nodeNumber2, 'nrOfPaths':0, 'diameter':float(dia[j][i-1])*avgScale})[0]
if gu.find_edge(G, eprop, {'coord1':vprop[v2]['coord'], 'coord2':vprop[v1]['coord'],'weight':((vprop[v1]['diameter']+vprop[v2]['diameter'])/2)**4,'RTP':False}):
pass
else:
e = G.add_edge(v1, v2)
epropW[e]=(((vprop[v1]['diameter']+vprop[v2]['diameter'])/2)/avgScale)**4
eprop[e]={'coord1':vprop[v1]['coord'], 'coord2':vprop[v2]['coord'],'weight':((vprop[v1]['diameter']+vprop[v2]['diameter'])/2)**4,'RTP':False}
else:
v2=G.add_vertex()
vprop[G.vertex(v2)]={'imgIdx':(j,i-1),'coord':nodeNumber2, 'nrOfPaths':0, 'diameter':float(dia[j][i-1])*avgScale}
e = G.add_edge(v1, v2)
epropW[e]=(((vprop[v1]['diameter']+vprop[v2]['diameter'])/2)/avgScale)**4
eprop[e]={'coord1':vprop[v1]['coord'], 'coord2':vprop[v2]['coord'],'weight':((vprop[v1]['diameter']+vprop[v2]['diameter'])/2)**4,'RTP':False}
except:pass
try:
if img[j + 1,i] == True:
nodeNumber2 = (float(i)*yScale,float(j+1)*xScale)
if gu.find_vertex(G, vprop, {'imgIdx':(j+1,i),'coord':nodeNumber2, 'nrOfPaths':0, 'diameter':float(dia[j+1][i])*avgScale}):
v2=gu.find_vertex(G, vprop, {'imgIdx':(j+1,i),'coord':nodeNumber2, 'nrOfPaths':0, 'diameter':float(dia[j+1][i])*avgScale})[0]
if gu.find_edge(G, eprop, {'coord1':vprop[v2]['coord'], 'coord2':vprop[v1]['coord'],'weight':((vprop[v1]['diameter']+vprop[v2]['diameter'])/2)**4,'RTP':False}):
pass
else:
e = G.add_edge(v1, v2)
epropW[e]=(((vprop[v1]['diameter']+vprop[v2]['diameter'])/2)/avgScale)**4
eprop[e]={'coord1':vprop[v1]['coord'], 'coord2':vprop[v2]['coord'],'weight':((vprop[v1]['diameter']+vprop[v2]['diameter'])/2)**4,'RTP':False}
else:
v2=G.add_vertex()
vprop[G.vertex(v2)]={'imgIdx':(j+1,i),'coord':nodeNumber2, 'nrOfPaths':0, 'diameter':float(dia[j+1][i])*avgScale}
e = G.add_edge(v1, v2)
epropW[e]=(((vprop[v1]['diameter']+vprop[v2]['diameter'])/2)/avgScale)**4
eprop[e]={'coord1':vprop[v1]['coord'], 'coord2':vprop[v2]['coord'],'weight':((vprop[v1]['diameter']+vprop[v2]['diameter'])/2)**4,'RTP':False}
except:pass
try:
if img[j - 1,i] == True:
nodeNumber2 = (float(i)*yScale,float(j-1)*xScale)
if gu.find_vertex(G, vprop, {'imgIdx':(j-1,i),'coord':nodeNumber2, 'nrOfPaths':0, 'diameter':float(dia[j-1][i])*avgScale}):
v2=gu.find_vertex(G, vprop, {'imgIdx':(j-1,i),'coord':nodeNumber2, 'nrOfPaths':0, 'diameter':float(dia[j-1][i])*avgScale})[0]
if gu.find_edge(G, eprop, {'coord1':vprop[v2]['coord'], 'coord2':vprop[v1]['coord'],'weight':((vprop[v1]['diameter']+vprop[v2]['diameter'])/2)**4,'RTP':False}):
pass
else:
e = G.add_edge(v1, v2)
epropW[e]=(((vprop[v1]['diameter']+vprop[v2]['diameter'])/2)/avgScale)**4
eprop[e]={'coord1':vprop[v1]['coord'], 'coord2':vprop[v2]['coord'],'weight':((vprop[v1]['diameter']+vprop[v2]['diameter'])/2)**4,'RTP':False}
else:
v2=G.add_vertex()
vprop[G.vertex(v2)]={'imgIdx':(j-1,i),'coord':nodeNumber2, 'nrOfPaths':0, 'diameter':float(dia[j-1][i])*avgScale}
e = G.add_edge(v1, v2)
epropW[e]=(((vprop[v1]['diameter']+vprop[v2]['diameter'])/2)/avgScale)**4
eprop[e]={'coord1':vprop[v1]['coord'], 'coord2':vprop[v2]['coord'],'weight':((vprop[v1]['diameter']+vprop[v2]['diameter'])/2)**4,'RTP':False}
except: pass
#
print '100.0%'
print 'selecting largest connected component'
G.edge_properties["ep"] = eprop
G.edge_properties["w"] = epropW
G.vertex_properties["vp"] = vprop
l = gt.label_largest_component(G)
print(l.a)
u = gt.GraphView(G, vfilt=l)
print '# vertices'
print(u.num_vertices())
print(G.num_vertices())
print '# edges'
print(u.num_edges())
print 'building graph finished in: '+str(time.time()-start)+'s'
return u
示例2: makeGraphFast
# 需要导入模块: from graph_tool import Graph [as 别名]
# 或者: from graph_tool.Graph import edge_properties["w"] [as 别名]
#.........这里部分代码省略.........
vList=vListLine2+list(vL)
else: vList=vListLine2+[vL]
line1=addedVerticesLine2+list(line1)
for jdx,j in enumerate(line1):
vprop[vList[jdx]]={'imgIdx':(j,idx),'coord': (float(j)*xScale,float(idx)*yScale), 'nrOfPaths':0, 'diameter':float(dia[idx][j])*avgScale}
'''
keep order of the inserted vertices
'''
sumAddVertices+=len(line1)
addedVerticesLine2=[]
vListLine2=[]
'''
Connect foreground indices to neighbours in the next line
'''
for v1 in line1:
va=vList[line1.index(v1)]
diagonalLeft = diagonalRight = True
try:
if img[idx][v1-1]==True:
diagonalLeft=False
vb=vList[line1.index(v1-1)]
e=G.add_edge(va,vb)
eprop[e]={'coord1':vprop[va]['coord'], 'coord2':vprop[vb]['coord'],'weight':((vprop[va]['diameter']+vprop[vb]['diameter'])/2),'RTP':False}
epropW[e]=2./(eprop[e]['weight']**2)
except:
print 'Boundary vertex at: '+str([v1,idx-1])+' image size: '+ str([w,h])
pass
try:
if img[idx][v1+1]==True:
diagonalRight=False
vb=vList[line1.index(v1+1)]
e=G.add_edge(va,vb)
eprop[e]={'coord1':vprop[va]['coord'], 'coord2':vprop[vb]['coord'],'weight':((vprop[va]['diameter']+vprop[vb]['diameter'])/2),'RTP':False}
epropW[e]=2./(eprop[e]['weight']**2)
except:
print 'Boundary vertex at: '+str([v1+1,idx])+' image size: '+ str([w,h])
pass # just if we are out of bounds
try:
if img[idx+1][v1]==True:
diagonalRight=False
diagonalLeft=False
vNew=G.add_vertex()
vprop[vNew]={'imgIdx':(v1,idx+1),'coord': (float(v1)*xScale,float(idx+1)*yScale), 'nrOfPaths':0, 'diameter':float(dia[idx+1][v1])*avgScale}
vListLine2.append(vNew)
e=G.add_edge(vList[line1.index(v1)],vNew)
eprop[e]={'coord1':vprop[va]['coord'], 'coord2':vprop[vNew]['coord'],'weight':((vprop[va]['diameter']+vprop[vNew]['diameter'])/2),'RTP':False}
epropW[e]=1./(eprop[e]['weight']**2)
if v1 not in addedVerticesLine2: addedVerticesLine2.append(v1)
except:
print 'Boundary vertex at: '+str([v1,idx+1])+' image size: '+ str([w,h])
pass
try:
if diagonalRight == True and img[idx+1][v1+1]==True:
vNew=G.add_vertex()
vprop[vNew]={'imgIdx':(v1+1,idx+1),'coord': (float(v1+1)*xScale,float(idx+1)*yScale), 'nrOfPaths':0, 'diameter':float(dia[idx+1][v1+1])*avgScale}
vListLine2.append(vNew)
e=G.add_edge(vList[line1.index(v1)],vNew)
eprop[e]={'coord1':vprop[va]['coord'], 'coord2':vprop[vNew]['coord'],'weight':((vprop[va]['diameter']+vprop[vNew]['diameter'])/2),'RTP':False}
epropW[e]=1.41/(eprop[e]['weight']**2)
if v1+1 not in addedVerticesLine2: addedVerticesLine2.append(v1+1)
except:
print 'Boundary vertex at: '+str([v1+1,idx+1])+' image size: '+ str([w,h])
pass
try:
if diagonalLeft == True and img[idx+1][v1-1]==True:
vNew=G.add_vertex()
vprop[vNew]={'imgIdx':(v1-1,idx+1),'coord': (float(v1-1)*xScale,float(idx+1)*yScale), 'nrOfPaths':0, 'diameter':float(dia[idx+1][v1-1])*avgScale}
vListLine2.append(vNew)
e=G.add_edge(vList[line1.index(v1)],vNew)
eprop[e]={'coord1':vprop[va]['coord'], 'coord2':vprop[vNew]['coord'],'weight':((vprop[va]['diameter']+vprop[vNew]['diameter'])/2),'RTP':False}
epropW[e]=1.41/(eprop[e]['weight']**2)
if v1-1 not in addedVerticesLine2: addedVerticesLine2.append(v1-1)
except:
print 'Boundary vertex at: '+str([v1-1,idx+1])+' image size: '+ str([w,h])
pass
try:
if img[idx][v1+1]==False and img[idx][v1-1]==False and img[idx+1][v1]==False and diagonalLeft==False and diagonalRight==False:
print 'tip detected'
if img[idx-1][v1-1]==False and img[idx-1][v1+1]==False and img[idx-1][v1]==False:
print 'floating pixel'
except:
pass
print'done!'
G.edge_properties["ep"] = eprop
G.edge_properties["w"] = epropW
G.vertex_properties["vp"] = vprop
print 'graph build in '+str(time.time()-start)
l = gt.label_largest_component(G)
u = gt.GraphView(G, vfilt=l)
print '# vertices'
print(u.num_vertices())
print(G.num_vertices())
if u.num_vertices()!=G.num_vertices(): self.__fail=float((G.num_vertices()-u.num_vertices()))/float(G.num_vertices())
return u,u.num_vertices()