Ejemplo n.º 1
0
def TestBansal():
    G = syn.InitRandom(10, makeInt=True)

    WG = G.copy()
    WG.remove_edges_from([(u, v) for (u, v, d) in WG.edges(data=True)
                          if d['weight'] < 0.0])

    viz.DrawGraph(WG, title='original')

    print("Trying Bansal")
    ban = bansal.BansalSolver(WG)
    components = ban.run()
    labels = dict()
    ci = 1
    for component in components:
        for v in component:
            labels[v] = ci
        ci = ci + 1

    E = seg.GetLabelEnergy(G, labels)
    print("Bansal energy is " + str(E))

    L = seg.GetLabelsAtThreshold(G, theta=0)
    E = seg.GetLabelEnergy(G, L)
    print("CC at zero is " + str(E))

    thresh, minE = seg.FindMinEnergyThreshold(G)
    print("CC min is " + str(minE))

    plt.show()
    print("Done")
Ejemplo n.º 2
0
def Minimize(WG, nodeType=None):

    if nodeType is None:
        nodeType = 'CC'

    #print("DsnNode: Minimizing...")
    param = dict()
    param['nodeType'] = nodeType

    if nodeType == 'CC':
        thresh, minE = seg.FindMinEnergyThreshold(WG)
        #print("WS Min  Energy: " + str(minE) + "           @ t=" + str(thresh))
        param['threshold'] = thresh
        L = seg.GetLabelsAtThreshold(WG, theta=thresh)
        #E2 = seg.GetLabelEnergy(WG, L)
        #print("Energy check: " + str(minE) + " verse " + str(E2))

    elif nodeType == 'WC':
        WC = seg.GetWatershedGraph(WG)

        thresh, minE = seg.FindMinEnergyThreshold(WC, eval=WG)
        #print("WS Min  Energy: " + str(minE) + "           @ t=" + str(thresh))
        param['threshold'] = thresh
        L = seg.GetLabelsAtThreshold(WC, theta=thresh)
        #E2 = seg.GetLabelEnergy(WG, L)
        #print("Energy check: " + str(E2))

    elif nodeType == 'WS':  # fixed threshold WC
        WC = seg.GetWatershedGraph(WG)

        param['threshold'] = 0.0
        L = seg.GetLabelsAtThreshold(WC, theta=0.0)
        minE = seg.GetLabelEnergy(WG, L)
        #print("Energy check: " + str(E2))

    #print("DsnNode: Done")
    return L, minE, param
Ejemplo n.º 3
0
def TestKruskal():
    #np.random.seed(1)
    WG = syn.InitRandom(10, 1, False)
    viz.DrawGraph(WG, title='original')

    # Get the labeling at threshold 0 and calculate energy
    L = seg.GetLabelsAtThreshold(WG, theta=0)
    E = seg.GetLabelEnergy(WG, L)
    print("Energy at zero is " + str(E))
    viz.DrawGraph(WG, labels=LG, title='original')

    # Find the best threshold and check it
    thresh, minE = seg.FindMinEnergyThreshold(WG)
    print("Minimum energy at " + str(thresh) + " is " + str(minE))
    # check to see if that's correct
    L = seg.GetLabelsAtThreshold(WG, theta=thresh)
    E2 = seg.GetLabelEnergy(WG, L)
    print("Energy check: " + str(E2))
    viz.DrawGraph(WG, labels=LG, title='bestThresh')

    plt.show()