我编写了一个代码来查找大量图像的像素的色调值。我在整个集合之前在50个图像上测试了我的代码,我获得了大约40%的0,272 293 582像素(正好110 064 805像素的色调值为'0')。
我的图片肯定没有那么多红色,所以问题可能来自哪里?以下是您可以复制它的方法:
from PIL import Image
import _imaging
import colorsys
import math
import os
numberofPix = 0
zeroCount = 0
for file in os.listdir("/path/"):
print str(file)
im = Image.open(file)
width, height = im.size
rgb_im = im.convert('RGB')
widthRange = range(width)
heightRange = range(height)
for i in widthRange:
for j in heightRange:
r, g, b = rgb_im.getpixel((i, j))
h, s, v = colorsys.rgb_to_hsv(r/255.0, g/255.0, b/255.0)
h = h * 360
h = int(round(h))
numberofPix = numberofPix +1
if h == 0:
zeroCount = zeroCount +1
print str(numberofPix)
print str(zeroCount)