예제 #1
0
    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)
    impath = np.zeros(imw.shape)
    for path in pathes:
        impath[tuple(pathes[path].T)] = path

if 0:
    # rM = rE*(rG<1e9)/(rG*(rG<1e9) + (rG>1e9))
    # rM = (rG >= 3*rE)
    rM = np.minimum(np.exp((rG - 3 * rE) / 10), 1)

    # Mcom = commute_time(1-rM)[ipoints,:][:,ipoints]
    # Mcom = Mcom - np.min(Mcom[np.where(np.triu(np.ones(Mcom.shape),k=1))])
    # Mcom.flat[::Mcom.shape[0]+1] = 0
    # Mcom /= np.c_[np.sum(Mcom, axis=1)]

    Aff = np.exp(-rG**2 / np.mean(rG[rG < 1e9] * 3)**2)
예제 #2
0
 points = np.c_[
     np.random.randint(0, shape[0], npoints),
     np.random.randint(0, shape[1], npoints),
     ]
 
 dist, labels, DM, inter_ = fastm.fast_marching_3d(
     speed, 
     points,
     offset=1,
     output_arguments=(
         'distances', 
         'labels', 
         'DM',
         'intersections',
         )
     )
 inter = np.argwhere(inter_!=-1)
 
 path = fastm.shortestpath(points, inter_, dist)
 path_ = np.argwhere(path!=-1)
 col = path[tuple(path_.T)]
 
 if 1:
     from matplotlib import pyplot
     pyplot.figure()
     pyplot.imshow(speed.T, cmap='gray', aspect='equal', interpolation='nearest')
     pyplot.imshow(labels.T,  alpha=0.8, interpolation='nearest')
     pyplot.scatter(points[:,0], points[:,1])
     pyplot.scatter(inter[:,0], inter[:,1], c='r')
     pyplot.scatter(path_[:,0], path_[:,1], c=col)
     pyplot.show()
예제 #3
0
    


    # 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)
    impath = np.zeros(imw.shape)
    for path in pathes:
        impath[tuple(pathes[path].T)] = path
        
if 0:  
    # rM = rE*(rG<1e9)/(rG*(rG<1e9) + (rG>1e9))
    # rM = (rG >= 3*rE)
    rM = np.minimum(np.exp((rG - 3*rE)/10),1)
    
    # Mcom = commute_time(1-rM)[ipoints,:][:,ipoints]
    # Mcom = Mcom - np.min(Mcom[np.where(np.triu(np.ones(Mcom.shape),k=1))])
    # Mcom.flat[::Mcom.shape[0]+1] = 0
    # Mcom /= np.c_[np.sum(Mcom, axis=1)]
    
    Aff = np.exp(-rG**2/np.mean(rG[rG<1e9]*3)**2)