wsDtSegmentation.py 文件源码

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

项目:nature_methods_multicut_pipeline 作者: ilastik 项目源码 文件源码
def remove_wrongly_sized_connected_components(a, min_size, max_size=None, in_place=False, bin_out=False):
    """
    Given a label image remove (set to zero) labels whose count is too low or too high.
    (Copied from lazyflow.)
    """
    original_dtype = a.dtype

    if not in_place:
        a = a.copy()
    if min_size == 0 and (max_size is None or max_size > numpy.prod(a.shape)): # shortcut for efficiency
        if (bin_out):
            numpy.place(a,a,1)
        return a

    component_sizes = vigra_bincount(a)
    bad_sizes = component_sizes < min_size
    if max_size is not None:
        numpy.logical_or( bad_sizes, component_sizes > max_size, out=bad_sizes )
    del component_sizes

    bad_locations = bad_sizes[a]
    a[bad_locations] = 0
    del bad_locations
    if (bin_out):
        # Replace non-zero values with 1
        numpy.place(a,a,1)
    return numpy.asarray(a, dtype=original_dtype)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号