def get_histogram(img):
if not img.mode.startswith('RGB'):
img = img.convert('RGB')
hist = img.histogram()
max_h = float(max(hist))
height = 180
with ui.ImageContext(430, height) as ctx:
a = 1
rgb = [(1, 0, 0, a), (0, 1, 0, a), (0, 0, 1, a)]
for i, color in enumerate(rgb):
ui.set_color(color)
for j, count in enumerate(hist[i*256:i*256+256]):
bar_height = count / max_h * (height - 5)
ui.fill_rect(2*j, height-bar_height, 2, bar_height)
return ctx.get_image()
评论列表
文章目录