[Image-SIG] antialiasing in pil -2

Kevin.Cazabon@gretag.com Kevin.Cazabon@gretag.com
Mon, 14 May 2001 08:54:14 -0600


Hi Kees;


The sample code you provide doesn't really perform anti-aliasing as I had
suggested... try something like this instead, and it will probably give you
a better/smoother result:

#

dxy=100
antialiasing=1
scale=4

if antialiasing:
     # create the ORIGINAL image at scale* resolution, don't size up an
already-created image
     # this way, you have finer detail that will result in smoother
anti-aliasing
     im = create_im(scale*dxy, scale*dxy)
else:
     im = create_im(dxy, dxy, scale)

if antialiasing:
     im = im.resize((dxy), Image.BICUBIC)


def create_im (width, height, scale=1):
     im = Image.new(width, height)
     object_size = object_size*scale
     # draw your objects...
     return im
#


Not much of a change above, but rendering all your data at scale*
resolution then scaling down with BICUBIC will create much smoother results
than scaling up using NEAREST then scaling down with BICUBIC.  The latter
will work, but will provide minimal anti-aliasing.

As for 1-pixel wide lines... if they're rendered at scale* the width you
want them to be when they're done, they'll be "OK", but 1-pixel
anti-aliased lines will always fade in/out.  I'd suggest that you set
1-pixel lines to be something like 1.5 pixels so that they show up better.
At 4* res, that would be 6 pixels wide.  I'm not sure how you'd set the
line width in Imagedraw, I've never tried it.

Kevin Cazabon







                                                                                                                   
                    Kees van                                                                                       
                    Drongelen /          To:     Kevin.Cazabon@gretag.com                                          
                    VisualSpace          cc:     image-sig@python.org                                              
                    <kees@visuals        Subject:     Re: [Image-SIG] antialiasing in pil -2                       
                    pace.nl>                                                                                       
                                                                                                                   
                    05/14/2001                                                                                     
                    02:53 AM                                                                                       
                                                                                                                   
                                                                                                                   




Thanks Kevin,

It works for filled objects. With outlined objects the line of 1
pixel is too thin. Do you know how-to manipulate the outline
thickness?

anyway thanks for your comment.

Kees van Drongelen.

#

dxy=100
antialiasing=1
scale=4

if antialiasing:
     im=im.resize((dxy[0]*scale, dxy[1]*scale), Image.NEAREST)
     im=im.resize((dxy), Image.BICUBIC)

#

>"Anti-Aliasing" by definition is performed by rendering at a higher
>resolution and downsampling using interpolation.  I'm not sure if PIL can
>automatically do this for you, but it's not hard to do yourself:
>
>-render at 2x, 3x, 4x, or higher resolution than you need
>-downsample the image using "bicubic" to the real size
>
>In other programs, you'll see the "Anti-aliasing" selection of "2x2, 3x3,
>4x4", etc, and that's bascially the "oversampling" you're setting above.
>
>Hope it helps...
>
>Kevin Cazabon
>


--
||||||||||||||||||||||||||||||||||||
VisualSpace
grafische en interactieve vormgeving

Krelagestraat 34
2012 CT Haarlem
T 023 532 33 66
F 023 532 33 04
http://www.visualspace.nl
||||||||||||||||||||||||||||||||||||