Implement prefilter in dask_image.ndinterp.map_coordinates using the dask_image spline_filter function
- Dominant language
- Python
- Stars
- 226
- Forks
- 56
- PR merge metrics
- No merged PRs in 30d
Description
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:
https://github.com/dask/dask-image/blob/9992f3f896edb674e4efec83b0bde2adf20ea69a/dask_image/ndinterp/_map_coordinates.py#L186-L190
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](https://github.com/dask/dask-image/pull/237#issuecomment-3521932133)
> 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
https://github.com/dask/dask-image/blob/9992f3f896edb674e4efec83b0bde2adf20ea69a/dask_image/ndinterp/_map_coordinates.py#L238
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](https://docs.pytest.org/en/stable/example/parametrize.html), instead of having to write an entirely new test.
Contributor guide
Research direction
Start in dask_image/ndinterp/_map_coordinates.py, especially the map_coordinates docstring and the da.map_blocks call around the cited lines. Read the existing map_coordinates tests and compare scipy.ndimage.map_coordinates with dask-image when prefilter=True. Done means prefiltering uses dask_image.ndinterp.spline_filter, the public default matches scipy, and the comparison test passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- computer-vision
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100