image.py 文件源码

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

项目:Comicolorization 作者: DwangoMediaVillage 项目源码 文件源码
def make_histogram(
        image_array,
        num_bins,
        multidim,
        threshold_palette=None,
        ranges=((0, 255), (0, 255), (0, 255)),
):
    # type: (any, any, bool, any, any) -> any
    channel, x, y = image_array.shape
    if not multidim:
        histogram_one = []
        for h_channel, range in zip(image_array, ranges):
            hist = numpy.histogram(h_channel, num_bins, range=range)[0]
            histogram_one.append(hist)
    else:
        h_each_channel = numpy.reshape(image_array, (channel, x * y)).T
        bins_each_channel = numpy.asarray([num_bins] * channel)
        histogram_one = numpy.histogramdd(h_each_channel, bins_each_channel, range=ranges)[0]

    hist = numpy.asarray(histogram_one) / (x * y)
    if threshold_palette is not None:
        palette = numpy.zeros(shape=hist.shape)
        palette[hist > threshold_palette] = 1
        hist = palette

    hist = hist.reshape(-1)
    return hist.astype(image_array.dtype)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号