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

Craig Coleman (C) Craig.Coleman at ordnancesurvey.co.uk
Tue Sep 13 18:56:02 CEST 2011


Hi all,
 
Thanks for all of the response.  In the end, I used a combination of
GDAL and Image Magick which are fast, reliable, extremely flexible and
free.  Subsequently, we now use Python to call out GDAL and Image Magick
as needed.
 
I changed my process to export to high resolution PDF in order to
preserve the quality as PDF is vector-based rather than use a very high
resolution TIFF.  I use gdal_translate with the --config
GDAL_PDF_DPI=400 option to reduce the resolution to 7874 which also
performs anti-aliasing on the fly as it happens.  After that, I use
Image Magick to map the 24-bit raster to an 8-bit raster using a colour
palette in another image - GDALs rgc2pct script can do this but it
always applies a dodgy Floyd Steinberg ditther which produces horrible
results, Image Magick can avoid the dither altogether somehow (clever
stuff).  Finally, I use gdal_translate again to ensure the GeoTIFF tags
are in place.  Voila - 8bit, 400dpi tiff is produced.
 
Thanks,

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 <http://www.ordnancesurvey.co.uk/>  |
craig.coleman at ordnancesurvey.co.uk 
Please consider your environmental responsibility before printing this
email. 

 


________________________________

From: andrew.k.wilson at gmail.com [mailto:andrew.k.wilson at gmail.com] On
Behalf Of Andrew Wilson
Sent: 13 September 2011 17:25
To: Craig Coleman (C)
Cc: image-sig at python.org
Subject: Re: [Image-SIG] What is the best way to anti-alias a very large
resolution image in PIL


Hello,
I've had similar problems with PIL, you may want to take a look at
OpenCV it can open rather large images and resize them.
  Thanks
  Andrew


On Thu, Sep 8, 2011 at 7:07 AM, 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 <tel:%2B44%20%280%29%202380%20054641>

	www.ordnancesurvey.co.uk <http://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
	
	



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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/image-sig/attachments/20110913/71cedbe4/attachment-0001.html>


More information about the Image-SIG mailing list