加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – 了解Pillow中的histogram()

发布时间:2020-12-20 12:24:13 所属栏目:Python 来源:网络整理
导读:来自文档: 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 conc
来自文档:

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,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,B = ? and
...
460  pixels with value of R = ?,B = ? and
...
3953 pixels with value of R = ?,B = 256

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读