A robot vision system can use a rolling average of a binary mask to estimate how much of a local window belongs to a candidate feature. If the mask is stored as unsigned bytes with values of zero and one, a filter that returns unsigned bytes can discard fractions before the next threshold sees them. The mask can look correct at acquisition while the local coverage calculation loses the feature.

Test the center of a known window

Use a three-by-three window with six ones and three zeros. Each row is identical, and all nine cells contribute to the center output. The expected center fraction is six divided by nine. Both calls below use the same neighborhood and edge handling. They differ only in the output data type.

import numpy as np

from scipy.ndimage import uniform_filter

roi = np.tile(np.array([0, 1, 1], dtype=np.uint8), (3, 1))

integer = uniform_filter(roi, size=3, mode="nearest")

floating = uniform_filter(roi, size=3, mode="nearest", output=np.float64)

assert integer[1, 1] == 0

assert np.isclose(floating[1, 1], 2 / 3)

assert not (integer[1, 1] >= 0.5)

assert floating[1, 1] >= 0.5

With SciPy 1.18.1 and NumPy 2.5.5, the integer call returns zero at the center. With floating-point output it returns approximately 0.667. At a cutoff of 0.5, the two results give different classifications of that same location.

Preserve precision inside the filter

SciPy's multidimensional uniform filter runs one-dimensional filters along the selected axes. It uses the output data type for the intermediate arrays. If a stage loses a fractional result, converting the finished integer array to a floating-point type cannot restore it. Request a floating-point output when the value represents a fraction and keep that type through the threshold comparison.

Check how the mask is encoded before interpreting the result. A zero-or-255 mask averages in the range from zero to 255 unless converted to zero and one first. A threshold intended as a fraction needs scores in the same units. Store the filtered score and the resulting boolean decision separately when reviewing false rejects.

Include an edge case in the acceptance fixture

The center window above stays entirely inside the mask, so it isolates the data-type effect. Add a border case that exercises the extension rule used in production. Nearest extension repeats edge values. Depending on the inspection definition, the calculation may instead require coverage over valid pixels only. In that case, track valid support independently and handle windows with no valid support before applying a threshold.

Keep the neighborhood dimensions, boundary rule, output data type, and threshold together in the test record. A small fixture with a hand-counted answer can reveal whether a later change in mask storage altered the decision.

Sources

SciPy multidimensional uniform filter reference for output type and intermediate arrays

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

SciPy one-dimensional uniform filter reference for window length and boundary behavior

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