question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SciPy N-D interpolation functions

See original GitHub issue

From @jakirkham on May 16, 2017 18:35

The list of functions below are what that this library intends to support with Dask Arrays. These all come from SciPy. In particular they come from scipy.ndimage.interpolation. The intent is to emulate their behavior with Dask Arrays as wrapping them is not likely to work. Will also include tests to verify these retain the behavior that the SciPy functions ordinarily have.

Copied from original issue: dask-image/dask-ndinterp#3

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:2
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
grlee77commented, Oct 9, 2020

Thanks @m-albert, this is interesting! I had been hoping to look at this at some point for GPU applications where memory limits can sometimes be an issue, so it is great to see this here.

In regards to the amount to pad the blocks, it is a little bit tricky, but I will explain what I think is the solution below. The first consideration are the samples that fall within the footprint of the spline kernel. I see you currently extend by 2 samples at each boundary to attempt to account for that which should be enough for all but order 5 where the filter is width 6.

Specifically, the spline interpolation kernel has width order + 1 with starting and (inclusive) ending samples used to interpolate a coordinate, x, given by the following function adapted from the C source

def coord_range(x, order=5):
    """Inclusive coordinate range for spline filter"""
    if order % 1:
        start = math.floor(x) - order // 2
    else:
        start = math.floor(x + 0.5) - order // 2
    stop = start + order
    return (start, stop)

So even for order 5, interpolating a value at location 0.2 for example would involve weights applied to samples from coordinate locations [-2, -1, 0, 1, 2, 3].

However, there is another, possibly more important consideration in the case of order > 1. For those cases, there is also a spline prefiltering step that involves application of an infinite impulse response (IIR) filter. In short this means there will be boundary errors in the prefiltering that decay with increasing distance from the block boundaries and may be noticeable for 10 or more samples. Rather than use a larger padding, the optimal workaround for that should be to first perform prefiltering independently via ndimage.spline_filter and then apply affine_transform with the argument prefilter=False.

spline_filter should be pretty trivial to split up for dask and avoid artifacts because it is separable across axes (i.e. spline_filter just applies spline_filter1d along each axis in turn). For dask-image, when filtering along axis n we should set it to have only 1 chunk on that axis to avoid boundary artifacts, but multiple chunks can be used on any of the other axes. Once you have the prefiltered result, proceed as proposed here, but using prefilter=False.

1reaction
m-albertcommented, Oct 9, 2020

Hey @jakirkham @GenevieveBuckley @wtbarnes @jni,

I wrote a function that implements ndimage.affine_transform for dask arrays and takes care of what @jni mentions, that in general input and output blocks are not aligned.

Here’s a gist containing the code with example usage and timing.

Would be cool to include this functionality in dask-image!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Interpolation (scipy.interpolate) — SciPy v1.9.3 Manual
As listed below, this sub-package contains spline functions and classes, 1-D and multidimensional (univariate and multivariate) interpolation classes, ...
Read more >
Interpolation (scipy.interpolate) — SciPy v1.9.3 Manual
A class representing an interpolant ( interp1d ) in 1-D, offering several interpolation methods. · Convenience function griddata offering a simple interface to ......
Read more >
scipy.interpolate.LinearNDInterpolator — SciPy v1.9.3 Manual
The interpolant is constructed by triangulating the input data with Qhull [1], and on each triangle performing linear barycentric interpolation. References.
Read more >
scipy.interpolate.interp1d — SciPy v1.9.3 Manual
. This class returns a function whose call method uses interpolation to find the value of new points. A 1-D array of real...
Read more >
scipy.interpolate.interpn — SciPy v1.9.3 Manual
Piecewise linear interpolant on unstructured data in N dimensions ... interpolation on grids with equal spacing (suitable for e.g., N-D image resampling).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found