Change in behavior of spline prefiltering - expected?
See original GitHub issueIt appears that, since scipy/scipy@81d5e7a, the behavior of spline interpolation has changed in a way that we (over at NIPY) found surprising.
In particular, as of that commit (I believe - see https://github.com/nipy/nipy/issues/468), we get a different result from direct use of scipy.ndimage.map_coordinates
compared to precalculating the spline filter, and sending that to scipy.ndimage.map_coordinates
. Here’s a script that demonstrates the change:
# Test 2D interpolation for Scipy
import numpy as np
import scipy.ndimage as spnd
arr = np.arange(6).reshape((2, 3))
coord = np.array([[0, 3]]).T
# Interpolation without calculating filter beforehand.
v1 = spnd.map_coordinates(arr,
coord,
order=3,
mode='nearest',
)
print('Calculate filter with interpolation', v1)
# Calculate and pass filter.
filtered = spnd.spline_filter(arr, order=3, mode='nearest')
v2 = spnd.map_coordinates(filtered,
coord,
order=3,
mode='nearest',
prefilter=False)
print('Calculate filter followed by interpolation', v2)
On Scipy 1.5.4 this gives [2.] and [2.]. On Scipy 1.6.0 this gives [2.] and [2.20261874] (macOS 11.2.1).
I was expecting precalculation to give the same results as no precalculation - as it used to in Scipy <= 1.5.4. Is that expectation not correct?
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (11 by maintainers)
Top Results From Across the Web
An Evaluation of Prefiltered B-Spline Reconstruction for Quasi ...
In this paper, we demonstrate that quasi-interpolation of orders two and four can be efficiently implemented on the Body-Centered Cubic (BCC) lattice by ......
Read more >A Fresh Look at Generalized Sampling - Hugues Hoppe
The input f is prefiltered using the cubic B-spline basis β3. The resulting over-blurred image is then transformed with a digital filter p∨...
Read more >Splines - A perfect fit for signal and image processing - EPFL
has changed significantly. This article attempts to fullfill three goals. The first is to provide a tutorial on splines that is geared to...
Read more >Mailman 3 Re: [Numpy-discussion] nd_image.affine_transform edge ...
I would rather opt for changing the spline fitting algorithm than for padding with ... but these problems with the spline prefiltering are...
Read more >Analyzing RNA-seq data with DESeq2 - Bioconductor
The DESeq2 model; Changes compared to DESeq; Methods changes since ... As input, the DESeq2 package expects count data as obtained, e.g., ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The difference here has to do with the
dtype
of the output. If unspecified,ndimage.interpolation
functions use the dtype of the input array to determine the dtype of the output. In your example, when calculatingv1
,arr
has an integer dtype, and sov1
is integer-valued as well. However, in the prefiltered case,filtered_and_padded.dtype
isnp.float64
so this gives a floating point result. This way of determining the output dtype has been present in ndimage for a long time and is not something new to the 1.6 release.To get equivalent floating point results for both you would do:
When computing
v1
, specifyoutput=np.float64
in themap_coordinates
call (or equivalently, castarr
tonp.float64
before callingmap_coordinates
)Or if the integer-valued output is the desired result
set
output=np.int64
(oroutput=arr.dtype
) in the computation ofv2_padded
Ouch - thank you! I’m so sorry to have accidentally made you do this debugging, rather than us - I’m afraid it was the classic problem of not enough tests on our side, then change of behavior (edges, ‘constant’) causing failures in the tests we did have, and then me writing more, new tests, without thinking to check what the results were previously.