[Numpy-discussion] neighborhood iterator

Zachary Pincus zachary.pincus@yale....
Mon Nov 23 14:25:12 CST 2009


Hi,

Having just written some cython code to iterate a neighborhood across  
an array, I have some ideas about features that would be useful for a  
general frame. Specifically, being able to pass in a "footprint"  
boolean array to define the neighborhood is really useful in many  
contexts. Also useful is the ability to query the offset of the  
current pixel from the center of the neighborhood. (These two  
features, plus very efficient handling of boundary conditions by  
breaking the image into regions where the conditions are and are not  
required, make the image iterators in ITK really nice to use.)

Zach


On Nov 23, 2009, at 9:12 AM, Nadav Horesh wrote:

>
> Thank you, this is a start. I seems that there are more issues to  
> resolve. I am trying to make a general frame that would enable one  
> to write filters using this iterator.
>
>
>   Nadav
>
> -----Original Message-----
> From: numpy-discussion-bounces@scipy.org on behalf of David Warde- 
> Farley
> Sent: Mon 23-Nov-09 03:21
> To: Discussion of Numerical Python
> Subject: Re: [Numpy-discussion] neighborhood iterator
>
>
> On 22-Nov-09, at 12:50 PM, Nadav Horesh wrote:
>
>>
>> I wonder if the neighbourhood iterator can be used as a more
>> efficient replacement for ndimage.generic_filter. Is there a way to
>> use it from cython?
>
> Yes, using the NumPy C API, called like any other C function is from
> Cython. Something like:
>
> ######################
>
> import numpy as np
> cimport numpy as np
>
> cdef extern from "numpy/arrayobject.h":
>     object PyArray_NeighborhoodIterNew(object iter, np.npy_intp  
> bounds,
>                                       int mode, object, np.ndarray
> fill_value)
>     int PyArrayNeighborhoodIter_Next(object iter)
>     int PyArrayNeighborhoodIter_Reset(object iter)
>
> ######################
>
> should do the trick.
>
> Note that you'll need to call np.import_array() before using any of
> these functions to initialize the C API, I think.
>
> David
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
> <winmail.dat>_______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion



More information about the NumPy-Discussion mailing list