下载此文档

python判断获取一张图片主色调的2个实例.doc


文档分类:办公文档 | 页数:约6页 举报非法文档有奖
1/6
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/6 下载此文档
文档列表 文档介绍
python判断获取一张图片主色调的2个实例
python判断、获取一张图片主色调的2个实例
作者: 字体:[增加 减小] 类型:转载
一幅图片,想通过程序判断获得其主要色调,应该怎么样处理?本文通过python实现判断、获取一张图片的主色调方法,需要的朋友可以参考下
python判断图片主色调,单个颜色:
复制代码 代码如下:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import colorsys
from PIL import Image
import optparse
def get_dominant_color(image):
"""
Find a PIL image's dominant color, returning an (r, g, b) tuple.
"""
image = ('RGBA')
# Shrink the image, so we don't spend too long analysing color
# frequencies. We're not interpolating so should be quick.
((200, 200))
max_score = None
dominant_color = None
for count, (r, g, b, a) in ([0] * [1]):
# Skip 100% transparent pixels
if a == 0:
continue
# Get color saturation, 0-1
saturation = (r / , g / , b / )[1]
# Calculate luminance - integer YUV conversion from
#
y = min(abs(r * 2104 + g * 4130 + b * 802 + 4096 + 131072) >> 13, 235)
# Rescale luminance from 16-235 to 0-1
y = (y - ) / (235 - 16)
# Ignore the brightest colors
if y > :
continue
# Calculate the score, preferring highly saturated colors.
# Add to the saturation so we don't completely ignore grayscale
# colors by multiplying the count by zero, but still give them a low
# weight.
score = (saturation + ) * count
if score

python判断获取一张图片主色调的2个实例 来自淘豆网www.taodocs.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数6
  • 收藏数0 收藏
  • 顶次数0
  • 上传人好用的文档
  • 文件大小25 KB
  • 时间2021-07-26