Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: generic_filter supports axes #20617

Open
Microdeep-ZL opened this issue Apr 30, 2024 · 1 comment
Open

ENH: generic_filter supports axes #20617

Microdeep-ZL opened this issue Apr 30, 2024 · 1 comment
Labels
enhancement A new feature or improvement scipy.ndimage

Comments

@Microdeep-ZL
Copy link

Is your feature request related to a problem? Please describe.

most filters accept the parameter axes, I'm wondering if it's possible to make generic_filter support axes as well.

Describe the solution you'd like.

generic_filter(data,getKCC,output=np.float32,footprint=np.ones((3,3,3)),axes=(0,1,2))

Describe alternatives you've considered.

I have a 4D ndarray, which a time series of 3D images. I want to compute Kendall's W (KCC) for every 3x3x3 cluster. Now my workaround is as follows

def getKCC(inputs,length,data):
    inputs=[slice(i,i+length) for i in inputs.astype(np.uint32)]
    indices=np.r_[*inputs]
    data=data.flat[indices].reshape(-1,length)

    # compute KCC
    var=data.mean(axis=0).var()
    return 12*var/(length-1)/(length+1)

# data.shape (40,40,40,3000)
length=data.shape[-1]
indices=np.arange(np.array(data.shape[:3]).prod(),dtype=np.uint32)*length
indices=indices.reshape(data.shape[:3])
generic_filter(indices,getKCC,output=np.float32,footprint=np.ones((3,3,3)),extra_arguments=(length,data))

Additional context (e.g. screenshots, GIFs)

No response

@Microdeep-ZL Microdeep-ZL added the enhancement A new feature or improvement label Apr 30, 2024
@Microdeep-ZL
Copy link
Author

I realized that I've misunderstood how axes works in other filters. Initially I thought axes=(0,1,2) would make the output have 3 dimensions rather than 4. In fact, even though generic_filter supports axes, this function call generic_filter(data,getKCC,output=np.float32,footprint=np.ones((3,3,3)),axes=(0,1,2)) will still result in an array with the same shape as data

Sorry for opening an immature issue. But anyways, I think it would be good to implement axes in generic_filter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A new feature or improvement scipy.ndimage
Projects
None yet
Development

No branches or pull requests

2 participants