python中histogram_python – 了解Pillow中的histogram()

来自文档:

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值