Re: Proposal: add axes argument to ndimage API

Ralf Gommers <[email protected]>
Newsgroups gmane.comp.python.scientific.devel
Message-ID <CABL7CQiQDJwnZtZ6iiHfgu6Y5hSfKRPxRXEDpQu1K+6qA-1K=A@mail.gmail.com>
On Fri, Mar 3, 2023 at 3:37 PM Gregory Lee <[email protected]> wrote:

> Hi all,
>
> Most functions in scipy.ndimage can be applied to n-dimensional images,
> but applying the functions along a subset of axes is not as easy as it
> could be. For separable filters there tends to already be a 1D variant
> where a single axis can be specified, but the n-dimensional versions do not
> currently have a corresponding axes argument.
>
> I am proposing that we can expose an axes argument on functions to
> simplify the process of filtering along a subset of axes (e.g. a common
> scenario would be filtering along only the spatial axes of an array that
> may contain other axes corresponding to color channels, timepoints or an
> image batch). Users can technically apply filters to a subset of axes now
> by manipulating the input arguments. For a few concrete examples of this:
>
> For gaussian filter, set sigma=0 along any axis that should not be
> filtered. For rank filters set size 1 along the non-filtered axes. For
> convolution-based filters or morphology the weights array can have
> singleton axes inserted.
>
> None of these are particularly difficult to implement, but it may not
> always be apparent to library users and an axes argument would be more
> convenient. The proposed implementation would be purely at the Python API
> level and is straightforward to implement and maintain.
>
> I opened a proof of concept PR implementing only *gaussian_filter *here:
> https://github.com/scipy/scipy/pull/18016
>
> I am happy to extend this to the rest of the filtering module in a follow
> up PR if the general approach looks good. It can also potentially be
> extended to morphology or other submodules as well.
>
> Let me know what you think
>

+1 from me, this sounds like a useful feature to add. Thanks for working on
this Greg!

Cheers,
Ralf

_______________________________________________
SciPy-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/scipy-dev.python.org/
Member address: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.