Skip to content, Skip to search


TrakEM2 Scripting

1,211 bytes added, 08:46, 16 October 2010
Compute the betweenness centrality of every node
centrality = e.getValue()
node.setColor(computeColor(centrality, maximum))
# Update display
# Show the tree in the 3D Viewer
== Compute the degree of every node ==
The degree of a node is the number of parent nodes that separate it from the root node. It's a built-in function in [ Tree] (and also in [ Node]):
In the following example, we colorize the tree based on the degree of the node: the closer to the root, the hotest:
<source lang="python">
from ini.trakem2.display import Display
from java.awt import Color
def computeColor(degree, highest):
blue = degree / float(highest)
red = 1 - blue
return Color(red, red, blue)
# Obtain the currently selected Tree in the canvas:
tree = Display.getFront().getActive()
# Compute betweenness centrality
degrees = tree.computeAllDegrees() # a java.util.Map
# Find out the maximum degree value, to scale:
maximum = reduce(max, degrees.values())
# Colorize each node according to its degree:
for e in degrees.entrySet():
node = e.getKey()
degree = e.getValue()
node.setColor(computeColor(degree, maximum))
# Update display
Emailconfirmed, uploaders