[Image-SIG] PIL anti-aliased scaling produces bad artifacts?
charmender at gmail.com
Sun Aug 8 18:11:18 CEST 2010
Hi. Forgive me if this has been brought up before, but I'm stumped. To
create anti-aliased edges of arbitrary shapes, I tried downscaling
enlarged versions of those shapes with the ANTIALIAS mode. This works
at first glance, but when zooming in, pixels with incorrect(?)
brightness can be noticed. Please try the following example code to
reproduce this problem:
from PIL import Image, ImageDraw
im = Image.new('RGB', (1500, 1000))
dr = ImageDraw.Draw(im)
dr.polygon((0, 0, 1250, 0, 250, 1000, 0, 1000), fill=(255, 255, 255))
im = im.resize((15, 10), Image.ANTIALIAS)
Zoom in far on the diagonal edge between the black and white areas of
the resulting test image. Looking from left to right or top to bottom
I expected the pixels to be increasingly dark. However, the order
seems to be: ...white -> light gray -> dark gray -> black -> *very
dark gray?!* -> black...
Is this intentional or not? If intentional, is there another way to
anti-alias edges with PIL (because I don't like these artifacts)?
More information about the Image-SIG