growPositions.py 文件源码

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

项目:imgProcessor 作者: radjkarl 项目源码 文件源码
def growPositions(ksize):
    '''
    return all positions around central point (0,0) 
    for a given kernel size 
    positions grow from smallest to biggest distances

    returns [positions] and [distances] from central cell

    '''
    i = ksize*2+1
    kk = np.ones( (i, i), dtype=bool)
    x,y = np.where(kk)
    pos = np.empty(shape=(i,i,2), dtype=int)
    pos[:,:,0]=x.reshape(i,i)-ksize
    pos[:,:,1]=y.reshape(i,i)-ksize

    dist = np.fromfunction(lambda x,y: ((x-ksize)**2
                                        +(y-ksize)**2)**0.5, (i,i))

    pos = np.dstack(
        np.unravel_index(
            np.argsort(dist.ravel()), (i, i)))[0,1:]

    pos0 = pos[:,0]
    pos1 = pos[:,1]

    return pos-ksize, dist[pos0, pos1]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号