[25, 129],
        [76, 25],
        [76, 77],
        [76, 129],
    ])

    _ipoints = np.unique(np.random.randint(0, np.prod(im.shape), 200))
    rpoints = np.c_[np.asarray(np.indices(im.shape))[0, :, :].flat[_ipoints],
                    np.asarray(np.indices(im.shape))[1, :, :].flat[_ipoints], ]

    # pyplot.figure()
    # pyplot.imshow(imw.T, cmap='gray')
    # pyplot.scatter(rpoints[:,0], rpoints[:,1])
    # pyplot.show()

    ipoints = np.argmin(distance_matrix.euclidian(points, rpoints), axis=1)
    npoints = len(ipoints)

    # geodesic distances
    rE = distance_matrix.euclidian(rpoints)
    rC = delaunay_2d.connectivity(rpoints)
    rG, rparents = fastm.fast_marching_3d_aniso(
        # im*np.mean(rE[rC==1]),
        imw,
        rpoints,
        heap_size=1e6,
        offset=1e-5,
        connectivity26=True,
        output_arguments=('DM', 'parents'),
    )
    pathes, connections = fastm.shortestpath(rparents)
Beispiel #2
0
    gt_ = np.where((ordering - np.c_[gt]) == 0)[1]

    print '\ncompute unary cost'
    nlabels = 1  #nnodes2
    ucost = 100

    print 'unary cost = %d for %d distinct labels' % (ucost, nlabels)
    labels = np.arange(nnodes2) % nlabels
    unary = (ordering % nlabels != np.tile(np.c_[gt % nlabels],
                                           (1, nnodes2))) * ucost

    use_proximity = True
    if use_proximity:
        thresh = step_size
        print 'use proximity with thresh = %f' % thresh
        DM_ = distm.euclidian(pt1, pt2)  # - thresh
        # DM_[DM_<0] = 0
        unary += DM_ / thresh + np.power(DM_ / thresh, 3.)

    print '\ncompute binary costs'
    if 'connectivity' not in dir():
        connectivity = 'full'  #'delaunay', 'full'

    if connectivity == 'delaunay':
        print '(delaunay connected graph)'
        pairs = delaunay.delaunay(pt1[:, 0], pt1[:, 1])[1]

    elif connectivity == 'smallworld':
        prop = 1
        print '(small world connected graph with %d pc random edges added)' % prop
        pairs = delaunay.delaunay(pt1[:, 0], pt1[:, 1])[1]
Beispiel #3
0
import numpy as np

from rmn.algebra import spectralg, distance_matrix as distm

pt1 = [
    [0,0],
    [0,1],
    [1,0],
    ]
pt2 = [
    [0.1,0.2],
    [-0.2,0.05],
    [0.0,0.1],
    [-0.1,0.97],
    [0.2,1.1],
    [1.2,0.0],
    ]

DM1 = distm.euclidian(pt1)
DM2 = distm.euclidian(pt2)    
    

A1 = 1./(1e-10 + DM1)
A2 = 1./(1e-10 + DM2)

w1,V1 = spectralg.laplacian_eigen_maps(A1,symmetric=True)
w2,V2 = spectralg.laplacian_eigen_maps(A2,symmetric=True)
Beispiel #4
0
        [76, 129],
        ])
    
    _ipoints = np.unique(np.random.randint(0, np.prod(im.shape), 200))
    rpoints = np.c_[
        np.asarray(np.indices(im.shape))[0,:,:].flat[_ipoints],
        np.asarray(np.indices(im.shape))[1,:,:].flat[_ipoints],
        ]
    
    # pyplot.figure()
    # pyplot.imshow(imw.T, cmap='gray')
    # pyplot.scatter(rpoints[:,0], rpoints[:,1])
    # pyplot.show()
    
        
    ipoints = np.argmin(distance_matrix.euclidian(points, rpoints), axis=1)
    npoints= len(ipoints)
    


    # geodesic distances
    rE = distance_matrix.euclidian(rpoints)
    rC = delaunay_2d.connectivity(rpoints)
    rG,rparents = fastm.fast_marching_3d_aniso(
        # im*np.mean(rE[rC==1]),
        imw,
        rpoints,
        heap_size=1e6,
        offset=1e-5,
        connectivity26=True,
        output_arguments=('DM','parents'),
import numpy as np

from rmn.algebra import spectralg, distance_matrix as distm

pt1 = [
    [0, 0],
    [0, 1],
    [1, 0],
]
pt2 = [
    [0.1, 0.2],
    [-0.2, 0.05],
    [0.0, 0.1],
    [-0.1, 0.97],
    [0.2, 1.1],
    [1.2, 0.0],
]

DM1 = distm.euclidian(pt1)
DM2 = distm.euclidian(pt2)

A1 = 1. / (1e-10 + DM1)
A2 = 1. / (1e-10 + DM2)

w1, V1 = spectralg.laplacian_eigen_maps(A1, symmetric=True)
w2, V2 = spectralg.laplacian_eigen_maps(A2, symmetric=True)
     ordering = np.tile(range(nnodes2),(nnodes1,1))
 gt_ = np.where((ordering-np.c_[gt])==0)[1]
 
 print '\ncompute unary cost'
 nlabels = 1 #nnodes2
 ucost = 100
 
 print 'unary cost = %d for %d distinct labels' %(ucost,nlabels)
 labels = np.arange(nnodes2)%nlabels
 unary = (ordering%nlabels != np.tile(np.c_[gt%nlabels],(1,nnodes2)))*ucost
 
 use_proximity = True
 if use_proximity:
     thresh = step_size
     print 'use proximity with thresh = %f' %thresh
     DM_ = distm.euclidian(pt1,pt2)# - thresh
     # DM_[DM_<0] = 0
     unary += DM_/thresh + np.power(DM_/thresh,3.)
 
 print '\ncompute binary costs'
 if 'connectivity' not in dir():
     connectivity = 'full'  #'delaunay', 'full'
 
 if connectivity=='delaunay':
     print '(delaunay connected graph)'
     pairs = delaunay.delaunay(pt1[:,0],pt1[:,1])[1]
     
 elif connectivity=='smallworld':
     prop = 1
     print '(small world connected graph with %d pc random edges added)' %prop
     pairs = delaunay.delaunay(pt1[:,0],pt1[:,1])[1]