A robot vision pipeline may shift an image by a fraction of a pixel before comparing it with a reference. If the calculation includes the edge of the frame, the boundary mode can affect the score even when the geometric shift and the padding value are unchanged. Test a feature that touches the border to see what the resampling step actually produces.

Check the first two output pixels

Consider a four-pixel row with intensity 8 at its left edge and zeros elsewhere. A positive shift of half a pixel samples the first output pixel at source coordinate -0.5. That coordinate lies outside the original row. With order-one interpolation and zero padding, SciPy's constant mode gives the fill value directly. In grid-constant mode the same query blends the padded zero at coordinate -1 with intensity 8 at coordinate 0, which gives 4. The second output pixel samples source coordinate 0.5, so both modes interpolate the same two original pixels and return 4.

import numpy as np

from scipy.ndimage import map_coordinates, shift

row = np.array([8.0, 0.0, 0.0, 0.0])

offset = 0.5

source_positions = np.arange(row.size, dtype=float) - offset

options = dict(order=1, cval=0.0, prefilter=False)

outside_fill = shift(row, offset, mode="constant", **options)

padded_blend = shift(row, offset, mode="grid-constant", **options)

coordinate_check = map_coordinates(

row, source_positions[None, :], mode="grid-constant", **options,

)

support = shift(np.ones_like(row), offset, mode="grid-constant", **options)

assert np.array_equal(outside_fill, [0.0, 4.0, 0.0, 0.0])

assert np.array_equal(padded_blend, [4.0, 4.0, 0.0, 0.0])

assert np.array_equal(coordinate_check, padded_blend)

assert np.array_equal(support, [0.5, 1.0, 1.0, 1.0])

The explicit coordinates in the map_coordinates call reproduce the shifted values and make the geometry visible in a test review. The all-ones input represents measured pixels, while its padded extension has value zero. Shifting it with the same linear interpolation gives a real-input weight of 0.5 at the first output position and 1.0 at the other three. The border intensity of 4 in the blended result thus includes a contribution from outside the measured image.

Carry coverage into the comparison

Keep floating-point input for the fixture so fractional intensities survive and the test isolates the boundary rule. For a two-dimensional image, record the row and column offsets in array-axis order and test a strip that crosses the shifted edge. A linear resampler can carry a support image alongside the intensities. Use that support when deciding whether to reject a partially covered pixel or include it under a documented scoring rule.

A visually acceptable border can still move an edge statistic when padded or mixed pixels contribute to its measurement. Compare both the edge strip and a fully supported interior strip when changing the resampler configuration. Preserve the interpolation order, boundary mode, fill value, and coverage rule in the test record so a later run can reproduce the comparison.

Sources

SciPy shift reference: https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.shift.html

SciPy map_coordinates reference: https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.map_coordinates.html