0

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()
SacreD
  • 363
  • 1
  • 5
  • 16
  • 2
    `.convert` seems to be a function part of the `Image` object... perhaps instead of `equalize(im.histogram())`, try `equalize(im)` – TerryA Jul 26 '17 at 09:21
  • 1
    `im.convert("L").histogram()` why are you expecting a list to have a `convert` method? – DeepSpace Jul 26 '17 at 09:21
  • @DeepSpace sorry i have really no idea, i am still trying to learn and understand how the code work. Do you mean that I should separate it? How should i work around with it? – SacreD Jul 26 '17 at 09:28
  • 1
    @TerryA you meant on line 24? I got more error. Traceback (most recent call last): File "C:/Users/310293649/AppData/Local/Programs/Python/Python36/equalize.py", line 27, in im = im.point(lut) File "C:\Users\310293649\AppData\Local\Programs\Python\Python36\lib\site-packages\PIL\Image.py", line 1464, in point return self._new(self.im.point(lut, mode)) TypeError: argument must be a sequence – SacreD Jul 26 '17 at 09:31
  • @MingKhaw Yes that is because you're returning something different than the link you showed us – TerryA Jul 26 '17 at 09:36
  • @TerryA i was testing the edited version of the script from the link in the " preserves image hue" scroll down to answer from Paul. Sorry my mistake for the confusion. I have updated the question. – SacreD Jul 26 '17 at 09:40

0 Answers0