[Numpy-discussion] "moving window" in numpy

Hans Meine meine at informatik.uni-hamburg.de
Mon Nov 26 03:04:38 EST 2007


On Montag 26 November 2007, Matthew Perry wrote:
> Hi all,
>
>  I'm not sure if my terminology is familiar but I'm trying to do a
> "moving window" analysis (ie a spatial filter or kernel) on a 2-D
> array representing elevation. For example, a 3x3 window centered on
> each cell is used to calculate the derivate slope of that cell.

Did you have a look at ndimage?
http://www.scipy.org/SciPyPackages/Ndimage

>  Currently I have tried implementing in pure python loops (too slow)

You could probably have a faster, pure python version with some indexing 
tricks.  E.g. if your gradient filter is static (i.e. the weights do not 
adapt to the local image content), you can apply it to whole images that 
contain shifted image contents.  This way, you're using the fast C loops of 
NumPy.

-- 
Ciao, /  /                                                    .o.
     /--/                                                     ..o
    /  / ANS                                                  ooo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20071126/69506f0c/attachment.sig>


More information about the NumPy-Discussion mailing list