[Image-SIG] What is the best way to anti-alias a very large resolution image in PIL

Fredrik Lundh fredrik at pythonware.com
Mon Oct 10 13:56:56 CEST 2011


Looks like you've found a working approach, but I'm still a bit
curious what "crash" means here -- do you get a segmentation violation
or a MemoryError exception?  PIL needs about 2G to load that image
into memory and an additional 50% of that to finish the resizing (it's
done in two passes), so you need decent hardware, but unless the
memory allocator is messing things up, it shouldn't crash hard if it
runs out of memory.

>>> from PIL import Image
>>> im = Image.new("RGB", (22633, 22633))
>>> im
<PIL.Image.Image image mode=RGB size=22633x22633 at 0x7F8E422C6248>
>>> out = im.resize((7874, 7874), Image.ANTIALIAS)
>>> out
<PIL.Image.Image image mode=RGB size=7874x7874 at 0x7F8E4230E320>
>>> ^Z
$ ps u | grep python
91700     3151 28.9 23.9 2982192 2946292 pts/0 TN   13:49   0:56 python

</F>

On 8 September 2011 13:07, Craig Coleman (C)
<Craig.Coleman at ordnancesurvey.co.uk> wrote:
> Hi,
>
> I have a really thorny problem.
>
> I need to downsample a raster map that is 23622x23622 pixels to 7874x7874
> pixels using the ANTIALIAS filter.
>
> I have the following Python code:
>
>>>> import Image
>>>> img = Image.open(r"C:\temp\24bit_nd.tif")
>>>> nimg = img.resize((7874,7874),Image.ANTIALIAS)
>
> As soon as the resize method is called, python crashes instantly.  I presume
> this is a memory allocation issue.
>
> Is there another way of performing anti-aliasing on such a large image (its
> 2.7GB uncompressed although I'm using LZW for storage).
>
> I have tried converting the file to 8bit with a palette and this
> successfully downsamples but the ANTIALIAS is not performed.  What am I
> doing wrong?
>
> Craig Coleman
> Technical Lead
> Information Systems, Ordnance Survey
> L0F2, Adanac Drive, SOUTHAMPTON, United Kingdom, SO16 0AS
> Phone: +44 (0) 2380 054641
> www.ordnancesurvey.co.uk | craig.coleman at ordnancesurvey.co.uk
> Please consider your environmental responsibility before printing this
> email.
>
> This email is only intended for the person to whom it is addressed and may
> contain confidential information. If you have received this email in error,
> please notify the sender and delete this email which must not be copied,
> distributed or disclosed to any other person.
>
> Unless stated otherwise, the contents of this email are personal to the
> writer and do not represent the official view of Ordnance Survey. Nor can
> any contract be formed on Ordnance Survey's behalf via email. We reserve the
> right to monitor emails and attachments without prior notice.
>
> Thank you for your cooperation.
>
> Ordnance Survey
> Adanac Drive
> Southampton SO16 0AS
> Tel: 08456 050505
> http://www.ordnancesurvey.co.uk
>
>
> _______________________________________________
> Image-SIG maillist  -  Image-SIG at python.org
> http://mail.python.org/mailman/listinfo/image-sig
>
>


More information about the Image-SIG mailing list