using networkx to run DAG of functions

Viewed 177

Please view this graph:

DAG sample

every node here should be an image processing function applying to ndarray of an input image. considering 3 path :

root>1>4

root>1>2>3

root>1>2>5

pencil me please, in networkx how can i use function as nodes? function a as node 1,function b as node 2,function c as node 3,and so

also how can i have all three output of 4,3,5 node as result while calculating function at node 1 only one time and function 2 only 2 times using networkx ?

import networkx as nx   

def a(ndarray_image):
    out = sharpen(ndarray_image)
    return (out)
def b(ndarray_image):
    out = lighten_r(ndarray_image)
    return (out)
def c(ndarray_image):
    out = lighten_g(ndarray_image)
    return (out)
def d(ndarray_image):
    out = lighten_b(ndarray_image)
    return (out)
def e(ndarray_image):
    out = smooth(ndarray_image,sigma=1.2)
    return (out)

G = nx.DiGraph()
nodes = ["root", "1", "2", "3", "4", "5"]
edges = [("root", "1"), ("1", "2"), ("1", "4"), ("2","5"), ("2", "3")]
G.add_nodes_from(nodes)
G.add_edges_from(edges)
0 Answers
Related