Re: [Numpy-discussion] moving window in numpy

2007-11-26 Thread Vincent Schut
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.
 
  Can this easily be implemented using numpy?
 

If I understand you correctly, scipy.ndimage does exactly what you ask
for. See http://www.scipy.org/SciPyPackages/Ndimage.

Cheers,
VS.

___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] moving window in numpy

2007-11-26 Thread Hans Meine
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


signature.asc
Description: This is a digitally signed message part.
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] moving window in numpy

2007-11-26 Thread Stefan van der Walt
Hi Matthew

On Sun, Nov 25, 2007 at 05:00:48PM -0800, Matthew Perry wrote:
  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.

Take a look at Anne Archibald's post:

http://projects.scipy.org/pipermail/numpy-discussion/2006-November/024760.html

and its attachment here:

http://projects.scipy.org/pipermail/numpy-discussion/attachments/20061120/d057cb0b/attachment.py

Regards
Stéfan
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] moving window in numpy

2007-11-25 Thread Matthew Perry
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.

 Can this easily be implemented using numpy?

 Currently I have tried implementing in pure python loops (too slow)
and c++ (fast but more difficult to compile, distribute, wrap in
python calls, etc). I think a good solution would be to leverage numpy
which is both fast and and easy package for end users to install.

 An example of the C++ code I'm trying to emulate is at
http://perrygeo.net/download/hillshade.html . Does anyone have any
tips or examples out there? Where should I start researching this?

-- 
Matthew T. Perry
http://www.perrygeo.net
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion