[SciPy-User] order_filter

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[SciPy-User] order_filter

Neal Becker
Is there a description of what is "order_filter"?

Googling for it is almost impossible (unless you want to order filters from amazon)

_______________________________________________
SciPy-User mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: order_filter

Warren Weckesser-2


On Thu, Sep 28, 2017 at 7:07 AM, Neal Becker <[hidden email]> wrote:
Is there a description of what is "order_filter"?

Googling for it is almost impossible (unless you want to order filters from amazon)



The word "order" is used in the sense of "order statistics" (https://en.wikipedia.org/wiki/Order_statistic).  The filter replaces each element with the `rank` element from the sorted list of values in its "neighborhood", where the neighborhood is determined by `domain`.  The values of "neighbors" outside the array are taken to be 0 (apparently).  It duplicates functionality provided by `scipy.ndimage.rank_filter` (https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.rank_filter.html).

For example,

In [27]: from scipy.signal import order_filter

In [28]: from scipy.ndimage import rank_filter

In [29]: np.random.seed(42)

In [30]: x = np.random.randint(1, 100, size=(5, 8))

In [31]: x
Out[31]:
array([[52, 93, 15, 72, 61, 21, 83, 87],
       [75, 75, 88, 24,  3, 22, 53,  2],
       [88, 30, 38,  2, 64, 60, 21, 33],
       [76, 58, 22, 89, 49, 91, 59, 42],
       [92, 60, 80, 15, 62, 62, 47, 62]])

In [32]: order_filter(x, np.ones((3, 3)), 0)
Out[32]:
array([[  0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.],
       [  0.,  15.,   2.,   2.,   2.,   3.,   2.,   0.],
       [  0.,  22.,   2.,   2.,   2.,   3.,   2.,   0.],
       [  0.,  22.,   2.,   2.,   2.,  21.,  21.,   0.],
       [  0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.]])

In [33]: rank_filter(x, 0, size=3, mode='constant')
Out[33]:
array([[ 0,  0,  0,  0,  0,  0,  0,  0],
       [ 0, 15,  2,  2,  2,  3,  2,  0],
       [ 0, 22,  2,  2,  2,  3,  2,  0],
       [ 0, 22,  2,  2,  2, 21, 21,  0],
       [ 0,  0,  0,  0,  0,  0,  0,  0]])

In [34]: order_filter(x, np.ones((3, 3)), 1)
Out[34]:
array([[  0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.],
       [  0.,  30.,  15.,   3.,   3.,  21.,  21.,   0.],
       [  0.,  30.,  22.,   3.,   3.,  21.,  21.,   0.],
       [  0.,  30.,  15.,  15.,  15.,  47.,  33.,   0.],
       [  0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.]])

In [35]: rank_filter(x, 1, size=3, mode='constant')
Out[35]:
array([[ 0,  0,  0,  0,  0,  0,  0,  0],
       [ 0, 30, 15,  3,  3, 21, 21,  0],
       [ 0, 30, 22,  3,  3, 21, 21,  0],
       [ 0, 30, 15, 15, 15, 47, 33,  0],
       [ 0,  0,  0,  0,  0,  0,  0,  0]])




Warren


_______________________________________________
SciPy-User mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/scipy-user



_______________________________________________
SciPy-User mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/scipy-user