[Image-SIG] PIL anti-aliased scaling produces bad artifacts?

David erwin94 at gmx.net
Sun Aug 8 21:06:44 CEST 2010


On Aug 8, 2010, at 6:11 PM, Angus wrote:
> 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:
[...]
> 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...

What you are seeing sounds like ringing artifacts from the lanczos
resampling of the ANTIALIAS mode (see
http://en.wikipedia.org/wiki/Lanczos_resampling ).

> Is this intentional or not? If intentional, is there another way to
> anti-alias edges with PIL (because I don't like these artifacts)?

You could try something like this:

im = im._new(im.im.stretch((15,10), Image.BILINEAR))

This will try to do an anti-aliased resizing, but use a bilinear filter
instead of the default lanczos filter. This will potentially have more
aliasing artifacts, but should have no ringing at all.

till then, David.



More information about the Image-SIG mailing list