level_lines.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:lddmm-ot 作者: jeanfeydy 项目源码 文件源码
def level_curves(fname, npoints, smoothing = 10, level = 0.5) :
    # Find the contour lines
    img = misc.imread(fname, flatten = True) # Grayscale
    img = img.T[:, ::-1]
    img = img / 255.
    img = gaussian_filter(img, smoothing, mode='nearest')
    lines = find_contours(img, level)

    # Compute the sampling ratio
    lengths = []
    for line in lines :
        lengths.append( arclength(line) )
    lengths = array(lengths)
    points_per_line = ceil( npoints * lengths / sum(lengths) )

    # Interpolate accordingly
    points = []
    connec = []
    index_offset = 0
    for ppl, line in zip(points_per_line, lines) :
        (p, c) = resample(line, ppl)
        points.append(p)
        connec.append(c + index_offset)
        index_offset += len(p)

    points = vstack(points)
    connec = vstack(connec)
    return Curve(points.ravel(), connec, 2) # Dimension 2 !
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号