Python 无法使用im.GetColor

Python 无法使用im.GetColor,python,python-imaging-library,pillow,Python,Python Imaging Library,Pillow,我正在尝试以下代码: im = Image.open("myimage") colors = im.getcolors() print colors 它返回“无”。所以我试了一下: im = Image.open("myimage") size = im.size colors = im.getcolors(size[0]*size[1]) 当我用这个“打印颜色”时,Python基本上崩溃了。我没有用大图像。我怎样才能让它工作 我的目标是从一张图像中知道有多少像素接近黑色,有多少像素

我正在尝试以下代码:

im = Image.open("myimage") 
colors = im.getcolors()
print colors
它返回“无”。所以我试了一下:

im = Image.open("myimage") 
size = im.size 
colors = im.getcolors(size[0]*size[1]) 
当我用这个“打印颜色”时,Python基本上崩溃了。我没有用大图像。我怎样才能让它工作


我的目标是从一张图像中知道有多少像素接近黑色,有多少像素接近白色。也许im.getcolors这不是正确的解决方案?

图像必须处于RGB模式才能使用
getcolors
。因此,请尝试:

    im_rgb = im.convert('RGB')
    colors = im_rgb.getcolors()
    print colors

你可以使用fun.getpixels()@AvinashBabu和.getpixels()我应该一个一个地分析它们,对吗?
im_rgb = im.convert('RGB')
colors = im_rgb.getcolors(maxcolors=1000000) #max colors to show
print(colors)