[Numpy-discussion] Help speeding up element-wise operations for video processing

Stéfan van der Walt stefan@sun.ac...
Tue Sep 16 03:50:58 CDT 2008

Hi Brendan

2008/9/16 brendan simons <spam4bsimons@yahoo.ca>:
> #interpolate the green pixels from the bayer filter image ain
> g = greenMask * ain
> gi = g[:-2, 1:-1].astype('uint16')
> gi += g[2:, 1:-1]
> gi += g[1:-1, :-2]
> gi += g[1:-1, 2:]
> gi /= 4
> gi += g[1:-1, 1:-1]
> return gi

I may be completely off base here, but you should be able to do this
*very* quickly using your GPU, or even just using OpenGL.  Otherwise,
coding it up in ctypes is easy as well (I can send you a code snippet,
if you need).

> I do something similar for red and blue, then stack the interpolated red,
> green and blue integers into an array of 24 bit integers and blit to the
> screen.
> I was hoping that none of the lines would have to iterate over pixels, and
> would instead do the adds and multiplies as single operations. Perhaps numpy
> has to iterate when copying a subset of an array?  Is there a faster array
> "crop" ?  Any hints as to how I might code this part up using ctypes?

Have you tried formulating this as a convolution, and using
scipy.signal's 2-d convolve or fftconvolve?


More information about the Numpy-discussion mailing list