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. For example, a mosaic of 7 images, each 800x600, the output size is about 8000x2000. Each output pixel is sampled from the source images using bilinear interpolation according to the inverse homography. The running time is nearly 1 hour.

State-of-the-art commercial mosaicking software (written in C) runs the above examples in less than 10 seconds!!!

Note that "State-of-the-art" image processing software is likely not only written in C, but also highly optimized -- taking into account cache sizes, using special instructions, etc, so you've not going to get close with naively written code. Still a factor of ten or so maybe.

I wonder how is other Python image processing applications' performance? Do we always need to implement slow functions in C?

in a word, yes -- if you are looping trough pixels in python, it's going to be painfully slow - python simply is not designed for that kind of thing.

E.g., I suppose to reimplement the bilinear interpolation in C, as it is called million times in Python, which is slow.

have you looked at the ndarray package? or PIL's interpolation for that matter? both are written in C.

If they don't have the algorithm you need, as a another poster pointed out, smart use of numpy will help a lot (essentially,l you are getting the inner loop in c via numpy)

If you have not idea how to do that, read up a bit on scipy.org, and then post a question to the numpy list.

Option 3 is Cython -- it lets you write C code in an almost-python syntax, and it understand numpy arrays, to it's really easy to re-write that inner loop in C.

-Chris





--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

chris.bar...@noaa.gov
_______________________________________________
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig

Reply via email to