[SciPy-User] Moving median code
josef.pktd at gmail.com
josef.pktd at gmail.com
Sun May 1 15:21:13 EDT 2011
On Sun, May 1, 2011 at 3:08 PM, Keith Goodman <kwgoodman at gmail.com> wrote:
> On Mon, Apr 25, 2011 at 8:31 AM, J. David Lee <johnl at cs.wisc.edu> wrote:
>> In working on a project recently, I wrote a moving median code that is
>> about 10x faster than scipy.ndimage.median_filter. It utilizes a linked
>> list structure to store values and track the median value. If anyone is
>> interested, I've posted the code here (about 150 lines):
>>
>> http://pages.cs.wisc.edu/~johnl/median_code/median_code.c
>
> I wrapped your moving window median code in cython. Here is how the
> timing scales with window size:
>
>>> a = np.random.rand(1e6)
>>> timeit move_median(a, window=10)
> 10 loops, best of 3: 44.4 ms per loop
>>> timeit move_median(a, window=100)
> 10 loops, best of 3: 179 ms per loop
>>> timeit move_median(a, window=1000)
> 1 loops, best of 3: 1.96 s per loop
>>> timeit move_median(a, window=10000)
> 1 loops, best of 3: 48.3 s per loop
>
> It would be interesting to compare the timings with a double heap
> algorithm [1] and with a C version of Wes's skiplist. I'll try to wrap
> the double heap next when I get a chance. BTW, what license are you
> using for your code?
>
> Here's the code I used. It's the first wrap I've done so suggestions
> welcomed. Now that I sort of know how, I'm going to wrap everything I
> see!
Is this an invitation to everyone to show you a function written in C?
Josef :)
More information about the SciPy-User
mailing list