来自文档:
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