TypeError at ImageMorph.LutBuilder#build_lut
VERSION = '1.1.7' # PIL version
PILLOW_VERSION = '4.1.1' # Pillow
If pattens has option 'N' (Negate), it causes TypeError: list indices must be integers or slices, not str. I think line 126 of ImageMorph.py is wrong.
# negate
if 'N' in options:
n = len(patterns)
for pattern, res in patterns[0:n]:
# Swap 0 and 1
pattern = (pattern
.replace('0', 'Z')
.replace('1', '0')
.replace('Z', '1'))
res = '%d' % (1-int(res)) # -> the reason for TypeError, maybe.
patterns.append((pattern, res))
@hhsprings Please could you give a minimal code example demonstrating the error, with the expected output?
the expected output?
sorry, I don't know. I just wanted to know this module's behaviors. In the official documents:
Operations:
4 - 4 way rotation N - Negate 1 - Dummy op for no other operation (an op must always be given) M - Mirroring
I could not understand this document well, so I tried to write samples:
from PIL import Image, ImageMorph
from PIL.ImageMorph import LutBuilder, MorphOp
img = Image.open("...")
img.load()
#lb = LutBuilder(op_name="edge")
lb = LutBuilder(patterns=['N:(... .0. .1.)->1'])
lut = lb.build_lut()
op = MorphOp(lut)
_, dimg = op.apply(img)
dimg.show()
This was likely fixed in https://github.com/python-pillow/Pillow/pull/2554, merged 11 days ago but not yet released; it'll be due out in 4.2.0 at the start of July.
Please could you test the master branch?
Please could you test the master branch?
I had checked it, and it's ok. Thanks.