Python AttributeError:' list'对象没有属性'转换'

时间:2017-07-26 09:19:35

标签: python image-processing pillow

我从保罗here的问题答案中得到了一些代码 我试图了解代码,但尝试运行时出现以下错误。我有谷歌周围,没有找到解决方案。有谁知道我应该怎么写它?对不起,我还是一个非常新的编程

RESTART:
C:/Users/310293649/AppData/Local/Programs/Python/Python36/equalize.py  Traceback (most recent call last):   File "C:/Users/310293649/AppData/Local/Programs/Python/Python36/equalize.py", line 24, in <module>
            lut = equalize(im.histogram())   
File "C:/Users/310293649/AppData/Local/Programs/Python/Python36/equalize.py", line 6, in equalize
            h = im.convert("L").histogram() 
AttributeError: 'list' object has no attribute 'convert'

这是代码。

import operator
from PIL import Image
from functools import reduce

def equalize(im):
    h = im.convert("L").histogram()
    lut = []
    for b in range(0, len(h), 256):
        # step size
        step = reduce(operator.add, h[b:b+256]) / 255
        # create equalization lookup table
        n = 0
        for i in range(256):
            lut.append(n / step)
            n = n + h[i+b]
    # map image through lookup table
    return im.point(lut*3)

if __name__ == "__main__":

    im = Image.open(r'R:\Temp\AlignedPhoto_in_PNG\Aligned_IMG_1789.png')

    # calculate lookup table
    lut = equalize(im.histogram())

    # map image through lookup table
    im = im.point(lut)
    im.show()

0 个答案:

没有答案