就是比如一张蓝天白云的照片,程序跑下来输出一个蓝色的颜色值给我,各位大佬能不能给一个现成的轮子啊?最好不要依赖太多安装包
1
hkitdog 2019-03-09 23:36:45 +08:00 via iPhone
用 php 做過,Python 應該差不多
<?php $image=imagecreatefromjpeg('image.jpg'); $thumb=imagecreatetruecolor(1,1); imagecopyresampled($thumb,$image,0,0,0,0,1,1,imagesx($image),imagesy($image)); $mainColor=strtoupper(dechex(imagecolorat($thumb,0,0))); echo $mainColor; ?> |
2
hkitdog 2019-03-09 23:45:28 +08:00 via iPhone
from PIL import Image
def compute_color(img): width, height = img.size r_total = 0 g_total = 0 b_total = 0 count = 0 for x in range(0, width): for y in range(0, height): r, g, b = img.getpixel((x,y)) r_total += r g_total += g b_total += b count += 1 return (r_total/count, g_total/count, b_total/count) img = Image.open('image.png') img_color = compute_color(img) print(img_color) #試了沒問題 |
3
mamahaha 2019-03-09 23:53:33 +08:00
每个像素点都查一下,感觉好狠啊
|
4
jdhao 2019-03-10 10:59:49 +08:00 via Android
这个需要聚类实现,事先设定要聚成几类,楼上计算 单通道均值不科学。
|