I got some code from the answer to this question by Paul here I am trying to learn about the code, but I got the following error when trying to run it. I had google around and found no solution to it. Anyone know how I should I write around it? Sorry I am still very new to programming
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'
Here is the code.
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()