0

In short:

I’m searching for a way to calculate a multidimensional custom image filter on more than one axis of values in python.

What I mean is:

With scipy’s ndimage, I can use ndimage.generic_filter to apply the custom function myfunc to an N-dimensional numpy array. In myfunc, I just need to indicate how to process the pixel neighborhood of shape (size[0],…,size[N-1]) which is passed to the function.

Slightly different from that, what I would like to do is to provide an array of shape (S1,…,SN,V1,…VM) and apply the filter only along the spatial dimensions and interpret the remaining M axes as axes of values. The pixel neighborhood to process would then be of shape (size[0],…,size[N-1],V1,…,VM).

So far I’m having my own relatively naive implementation of such a filter, however it would be good to have a version handling the general case and dealing with border effects.

Thanks a lot in advance for hints or ideas! Cheers

  • So, you want to aggregate only on one dimension? Just use .apply and specify the axis? – Rushabh Mehta Aug 07 '18 at 15:13
  • Hi @RushabhMehta, I want to apply a filter function to my array which processes not only a given element (such as when using apply) but an entire neighborhood around it. – jimmy_jammy Aug 07 '18 at 15:19
  • What do you mean by neighborhood – Rushabh Mehta Aug 07 '18 at 15:19
  • @RushabhMehta As provided by scipy.ndimage.filters.generic_filter: "At each element the provided function is called. The input values within the filter footprint at that element are passed to the function as a 1D array of double values." (https://docs.scipy.org/doc/scipy-0.16.1/reference/generated/scipy.ndimage.filters.generic_filter.html) – jimmy_jammy Aug 07 '18 at 15:27
  • I see now. I'm not convinced you will find a vectorized version of this. I think it depends on the function. – Rushabh Mehta Aug 07 '18 at 15:28
  • I'm hoping for the data passing to be optimised. Although I'm not sure whether this actually makes a difference. – jimmy_jammy Aug 07 '18 at 15:33
  • It's true that vectorization depends on the function. Something analogous to the scipy one would already be helpful though, to handle the borders and more (edited the question). – jimmy_jammy Aug 07 '18 at 16:11

0 Answers0