An inspection script starts from a known point on a metal coupon and expands through pixels that pass a segmentation test. In a low-resolution mask, two regions may meet along a diagonal even when their nearest pixels share no side. The result of expanding from the original point then depends on what the script treats as a neighbor.
Keep the seed and the allowed mask fixed
The fixture below has two allowed blocks of four pixels and a single seed in the upper left. The seed starts inside the allowed mask. SciPy's binary propagation extends the seed using the chosen neighborhood until it stops changing. Changing the neighborhood from side neighbors to side and corner neighbors leaves the allowed mask unchanged.
import numpy as np
from scipy.ndimage import binary_propagation, generate_binary_structure
allowed = np.array([
[1, 1, 0, 0],
[1, 1, 0, 0],
[0, 0, 1, 1],
[0, 0, 1, 1],
], dtype=bool)
seed = np.zeros_like(allowed)
seed[0, 0] = True
sides = generate_binary_structure(2, 1)
corners = generate_binary_structure(2, 2)
side_region = binary_propagation(seed, structure=sides, mask=allowed)
corner_region = binary_propagation(seed, structure=corners, mask=allowed)
assert side_region.sum() == 4
assert not side_region[2, 2]
assert corner_region.sum() == 8
assert corner_region[2, 2]
assert not (corner_region & ~allowed).any()
In SciPy 1.18.1 and NumPy 2.5.5, side-only propagation stops after reaching the upper-left block. The lower-right block is reachable when diagonal steps are permitted because pixel (1, 1) borders pixel (2, 2) at a corner. Every reached pixel still passes the same mask. The change comes from the available paths through that mask.
Verify the inspection rule at the relevant resolution
Save the seed coordinates and neighborhood rule with the mask used for the decision. Keep a corner-contact fixture and an edge-contact fixture in the test set. If the seed is found by another stage, check that it is inside the allowed region before expanding from it. If image crops or scaling change pixel coordinates, verify the seed and mask are aligned after that transform.
Physical contact needs evidence from the imaging setup and inspection tolerance. The pixel rule tells the script how to interpret the segmented grid at its current resolution. If a one-pixel connection changes the inspection outcome, retain the original image and review how the segmentation produced that connection.
Sources
SciPy binary_propagation reference for propagation within a mask
https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.binary_propagation.html
SciPy generate_binary_structure reference for neighborhood connectivity
https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.generate_binary_structure.html