Skip to content

Implement prefilter in dask_image.ndinterp.map_coordinates using the dask_image spline_filter function #419

@GenevieveBuckley

Description

@GenevieveBuckley

Currently, if you run map_coordinates with the keyword argument prefilter=True, the results do not exactly match the equivalent results from scipy. See this docstring comment by Marvin:

Warning: prefilter is True by default in
`scipy.ndimage.map_coordinates`. Prefiltering here is performed on a
chunk-by-chunk basis, which may lead to different results than
`scipy.ndimage.map_coordinates` in case of chunked input arrays
and order > 1.

As a hacky workaround, currently we have prefilter=False as the default in dask-image, but this is not ideal behaviour. It's not great because that does not match the default behaviour of the scipy.ndimage.map_coordinates function.

@astrofrog suggests

What if dask_image.ndinterp.map_coordinates did this automatically, e.g. using dask_image.ndinterp.spline_filter automatically if prefilter=True?
I think once this release is out, it would be worth investigating properly implementing prefilter=True using dask-image's spline_filter as you noted, so that prefilter could actually default to True here.

I think that's a great idea. Then we would get identical results from the scipy and dask-image map_coordinates functions when prefilter=True.

Rough approach:

  1. In the dask_image.ndinterp.map_coordinates function, add an initial step - if the prefilter kwarg is True, then add a step manually prefiltering the array using the dask_image.ndinterp.spline_filter function.
  2. Then change the default kwargs
    a. Set prefilter to False in the output = da.map_blocks(_map_single_coordinates_array_chunk, ... prefilter=False) part (since the input arrays are already pre-filtered with the dask-image spline interpolation

    b. Set prefilter to True in the outer dask-image map_coordinates function signature (in order to match the scipy map_coordinates implementation)
  3. Add a test for this, ensuring the results from scipy's map_coordinates match the dask-image map_coordinates results when prefilter=True. Probably you could extend the existing test with pytest input parameters, instead of having to write an entirely new test.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions