Home > Backend Development > Python Tutorial > python获取图片颜色信息的方法

python获取图片颜色信息的方法

WBOY
Release: 2016-06-10 15:17:11
Original
2403 people have browsed it

本文实例讲述了python获取图片颜色信息的方法。分享给大家供大家参考。具体分析如下:

python的pil模块可以从图片获得图片每个像素点的颜色信息,下面的代码演示了如何获取图片所有点的颜色信息和每种颜色的数量。

from PIL import Image
image = Image.open("jb51.gif")
image.getcolors()
Copy after login

返回结果如下

复制代码 代码如下:
..., (44, (72, 64, 55, 255)), (32, (231, 208, 141, 255)), (2368, (70, 64, 55, 255)),
(1, (187, 210, 216, 255)), (256, (68, 64, 57, 255)), (592, (67, 80, 103, 255)),
(2, (198, 204, 214, 255), ...
 
返回结果是一个元祖,每个元素的格式如下: (44, (72, 64, 55, 255)),其中(72,64,55,255)表示RGBA颜色,A就是透明度,44表示jb51.gif这张图片中包含了44个这种颜色。

希望本文所述对大家的Python程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template