image_stats.py 文件源码

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

项目:skan 作者: jni 项目源码 文件源码
def mesh_sizes(skeleton):
    """Compute the area in pixels of the spaces between skeleton branches.

    This only makes sense for 2D images.

    Parameters
    ----------
    skeleton : array, shape (M, N)
        An image containing a single-pixel-wide closed skeleton.

    Returns
    -------
    sizes : array of int, shape (P,)
        The sizes of all spaces delineated by the skeleton *not* touching
        the borders.

    Examples
    --------
    >>> image = np.array([[0, 0, 1, 0, 0],
    ...                   [0, 0, 1, 1, 1],
    ...                   [0, 0, 1, 0, 0],
    ...                   [0, 1, 0, 1, 0]])
    >>> print(mesh_sizes(image))
    []
    >>> from skan.nputil import pad
    >>> image2 = pad(image, 1)  # make sure mesh not touching border
    >>> print(mesh_sizes(image2))  # sizes in row order of first pixel in space
    [7 2 3 1]
    """
    spaces = ~skeleton.astype(bool)
    labeled = ndi.label(spaces)[0]
    touching_border = np.unique(np.concatenate((labeled[0], labeled[-1],
                                                labeled[:, 0],
                                                labeled[:, -1])))
    sizes = np.bincount(labeled.flat)
    sizes[touching_border] = 0
    sizes = sizes[sizes != 0]
    return sizes
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号