<jupyter_start><jupyter_text>Test SKNW for Cahn-Hillard dataset.<jupyter_code>#os.chdir(r'/Users/devyanijivani/git/pygraspi/notebooks/data')
dest = "/Users/devyanijivani/git/pygraspi/notebooks/junctions"
myFiles = glob.glob('*.txt')
myFiles.sort()

for i, file in enumerate(myFiles):
    morph = np.array(pandas.read_csv(file, delimiter=' ', header=None)).swapaxes(0, 1)
    skel, distance = medial_axis(morph, return_distance=True)
    graph = sknw.build_sknw(skel)
    for (s,e) in graph.edges():
        ps = graph[s][e]['pts']
        plt.plot(ps[:,1], ps[:,0], 'green', zorder=-1)

    # draw node by o
    nodes = graph.nodes()
    ps = np.array([nodes[i]['o'] for i in nodes], dtype = int)
    plt.scatter(ps[:,1], ps[:,0], s = 1, c ='r')

    # title and show
    plt.title('Build Graph')
    
    plt.gca().set_aspect('equal')
    print(os.path.splitext(file)[0])
    
    file_loc = os.path.join(dest, os.path.splitext(file)[0]+'.png')
    #print(file_loc)
    #plt.savefig(file_loc,dpi=1200)
    
    plt.close()

pwd
def skeletonize(morph):
    skel, distance = medial_axis(morph, return_distance=True)
    return skel, distance    
morph = np.array([[1,1,1],\
                [1,1,1],\
                [1,1,1]])
skel = skeletonize(morph)[0]
skel
def getEndJunction(graph):
    l = [graph.degree[n] for n in graph.nodes()]
    return np.array([l.count(1), l.count(3)])

graph = sknw.build_sknw(skel)
getEndJunction(graph)
def getBranchLen(graph):
    b_l = [graph.edges[e]['weight'] for e in graph.edges()]
    return np.array([len(b_l), round(sum(b_l)/len(b_l), 2)])        

getBranchLen(graph)<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup