get_segmentation.py 文件源码

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

项目:LabelsManager 作者: SebastianoF 项目源码 文件源码
def intensity_segmentation(in_data, num_levels=5):
    """
    :param in_data: image data in a numpy array.
    :param num_levels: maximum allowed 65535 - 1.
    :return: segmentation of the result in levels levels based on the intensities of the in_data.
    """
    # NOTE: right extreme is excluded, must be considered in outside the for loop.
    segm = np.zeros_like(in_data, dtype=np.uint16)
    min_data = np.min(in_data)
    max_data = np.max(in_data)
    h = (max_data - min_data) / float(int(num_levels))

    for k in xrange(0, num_levels):
        places = (min_data + k * h <= in_data) * (in_data < min_data + (k + 1) * h)
        np.place(segm, places, k)

    places = in_data == max_data
    np.place(segm, places, num_levels-1)

    return segm
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号