[Image-SIG] Resizing images

Douglas Bagnall douglas at paradise.net.nz
Fri Feb 23 00:57:16 CET 2007


Chris MacKenzie wrote:

>> My Question is will resizing in PIL reduce the image quality compared to 
>> CS2 or will it remain the same as the CS2 output.

I don't know about Photoshop, but this thread

http://mail.python.org/pipermail/image-sig/2005-May/003310.html

will tell you that this function:

def stretch(im, size, filter=Image.NEAREST):
    im.load()
    im = im._new(im.im.stretch(size, filter))
    return im

gives pixel-identical results to the Gimp's best resize method, if you
use PIL 1.1.6.  With 1.1.5, the results might be offset by half a pixel,
but you won't notice that unless you are making very small images.

If you don't actually need identical results, but are happy enough with
something that looks fine, then im.resize(size, Image.ANTIALIAS) should
work.

John Barratt wrote:

> Looking at PIL and the resize function we have the following methods :
> 
> NEAREST (use nearest neighbour),
> BILINEAR  (linear interpolation in a 2x2 environment),
> BICUBIC  (cubic spline interpolation in a 4x4 environment), or
> ANTIALIAS (a high-quality downsampling filter)
> 
> I would expect that the first three should produce identical results to 
> Photoshop, though there could be some variation to the implementation of 
> the algorithm in some methods. 

Actually this isn't the case -- apart from ANTIALIAS, the PIL resize
modes are bad at downsampling.


douglas




More information about the Image-SIG mailing list