[Image-SIG] Performance for image processing in Python

Guy K. Kloss g.kloss at massey.ac.nz
Mon Apr 19 05:28:05 CEST 2010

On Mon, 19 Apr 2010 14:31:41 Son Hua wrote:
> I'm quite new Python here. Recently I wrote an image mosaicking 
> application in Python (using Numpy library). It turns out that the 
> performance is quite terrible. [...]
> State-of-the-art commercial mosaicking software (written in C) runs the 
> above examples in less than 10 seconds!!!
> I wonder how is other Python image processing applications' performance? 
> Do we always need to implement slow functions in C? E.g., I suppose to 
> reimplement the bilinear interpolation in C, as it is called million 
> times in Python, which is slow.

Well, as you stated: You seem to be fairly new to Python. Just *using* NumPy 
does not guarantee good performance. The trick is to *use it right*. One 
example in C is for example also to use the right order of iterating over 
multi dimensional arrays to get the right performance. Otherwise you may be 
playing against the cache, which is fairly common on huge data structures.

So, one thing you ought to look for in your code is that you're for example 
*not* iterate over the elements of an array (pixelx), but use operations that 
are to be applied to the whole array at once. You can use these with most 
basic and more complex operations, e. g. multiply/divide/add/subtract a 
scalar, apply certain NumPy provided functions (g. g. sin() or log()), apply 
dot-product multiplication, etc.

Doing that, you can probably eliminate orders of magnitude of slowdown 



Guy K. Kloss
Institute of Information and Mathematical Sciences
Te Kura Pūtaiao o Mōhiohio me Pāngarau
Massey University, Albany (North Shore City, Auckland)
473 State Highway 17, Gate 1, Mailroom, Quad B Building
voice: +64 9 414-0800 ext. 9266   fax: +64 9 441-8181
G.Kloss at massey.ac.nz http://www.massey.ac.nz/~gkloss
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.python.org/pipermail/image-sig/attachments/20100419/81f26f53/attachment.pgp>

More information about the Image-SIG mailing list