[Image-SIG] Speeding up image.resize()
Jeff Epler
jepler at unpythonic.net
Tue Oct 19 01:56:43 CEST 2004
After seeing how slow image.resize() is, especially ANTIALIAS, I looked
at the underlying code in libImaging.
I examined the object code produced for Antialias.c. On my system
(linux on intel) not only is there a function call for XXX_filter, but
antialias_filter has more function calls inside as well (including a
call to libm's sin())
To improve the speed, I made all the XXX_filter functions (including
sinc_filter) 'static inline', and moved most of the body of
ImagingStretch into an include file, which is included once for each
filter. ImagingStretch now dispatches to one of the 4 _XXX_filter
functions, instead of merely setting some function pointers.
I also set some extra_compile_args appropriate for my system and
compiler:
exts = [(Extension(
"_imaging", files, libraries=libs, define_macros=defs,
extra_compile_args=['-O3', '-march=pentium4', '-mfpmath=sse',
'-msse2', '-ffast-math', '-mno-ieee-fp']
))]
In their current form, I doubt these changes are suitable for inclusion
in Imaging (because of the use of the "inline" extension and specialized gcc
compiler flags). However, I thought this might be helpful to someone.
If there's interest, I can produce a patch.
How much difference? I used 'timeit' on Imaging-1.1.5b1 and my modified
version of it. I tested on a laptop with a 1.5GHz Pentium-M CPU, with
SpeedStep disabled.
The script:
import Image
i=Image.open('test.jpg')
i.thumbnail((1024,768), Image.ANTIALIAS)
i.load()
test.jpg is a 3072x2048 digital camera image, which (I assume) is
loaded as 1532x1024 and resized to 1024x682.
1.1.5b1 gives:
10 loops, best of 3: 1.24e+06 usec per loop (1240 msec)
My version gives:
10 loops, best of 3: 6.99e+05 usec per loop (699 msec)
That's a 43% speedup.
Here's data for all filters:
(times in msec)
Filter Vanilla Patched Speedup
ANTIALIAS 1240 699 43%
BICUBIC 783 626 20%
BILINEAR 576 439 23%
NEAREST 411 517 -26% (!)
Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.python.org/pipermail/image-sig/attachments/20041018/5c5d5b68/attachment.pgp
More information about the Image-SIG
mailing list