Re: Performance for image processing in Python

"Guy K. Kloss" <[email protected]>
Newsgroups gmane.comp.python.image
Organization IIMS - Massey University
Message-ID <[email protected]>
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 
already.

HTH,

Guy

-- 
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
[email protected] http://www.massey.ac.nz/~gkloss

_______________________________________________
Image-SIG maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/image-sig
signature.asc (application/pgp-signature, 197 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEABECAAYFAkvLzcYACgkQpsb+VXwam+SrzwCeIZ9nSEUMI08cojlmF8Hx9QR6
acYAn193PY9S+IZrBXxuD7iHgsY12PXo
=/M9w
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.