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)
评论列表
文章目录