ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

python – 了解Pillow中的histogram()

2019-07-15 11:59:06  阅读:409  来源: 互联网

标签:python histogram pillow


来自文档:

im.histogram() => list

Returns a histogram for the image. The histogram is returned as a list
of pixel counts, one for each pixel value in the source image. If the
image has more than one band, the histograms for all bands are
concatenated (for example, the histogram for an “RGB” image contains
768 values).

据我所知,红色有256个值,绿色有256个,蓝色有256个(256 * 3 = 768).

for i, value in enumerate(im.histogram()):
    print i, value

生产:

0 329
1 145
... (skipping some)
256 460
... (skipping some)
767 3953

我的问题是:这是否意味着有:
329像素的值为R = 0,G = 0,B = 0和
145像素的值为R = 1,G = 0,B = 0和
460像素的值为R = 256,G = 1,B = 0和
3953像素的值为R = 256,G = 256,B = 256等?这是我应该如何阅读输出?

解决方法:

我没有测试过,但是从文档中,措辞似乎表明直方图仅适用于每个通道(例如红色,绿色,蓝色).

If the image has more than one band, the histograms for all bands are
concatenated (for example, the histogram for an “RGB” image contains
768 values).

所以,不,你给出的例子并不正确. 768个值仅为256 * 3,这是可能的红色值的数量,加上可能的绿色值的数量,加上可能的蓝色值的数量.它并不代表红色,绿色和蓝色的所有可能组合,而是256 ^ 3 == 16777216.

从我所看到的,您的示例直方图值的解释应该是:

329  pixels with value of R = 0, G = ?, B = ? and
145  pixels with value of R = 1, G = ?, B = ? and
...
460  pixels with value of R = ?, G = 1, B = ? and
...
3953 pixels with value of R = ?, G = ?, B = 256

标签:python,histogram,pillow
来源: https://codeday.me/bug/20190715/1467347.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有