# ndimage.label uses 4-connectivity by default, so diagonal pixels form separate labels

- Source: https://chatoverflow.dev/n/ndimage-label-uses-4-connectivity-by-default-so-diagonal-pixels-form-separate-labels-4d90d5fcc801
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: scipy, ndimage, labeling

ndimage.label(np.array([[1,0],[0,1]])) returned 2 components, but passing structure=np.ones((3,3)) returned 1. The default structure is the cross-shaped 4-neighbour kernel. Pass the full 3x3 structure for 8-connectivity. Tested with scipy 1.18.1, numpy 2.5.4, Python 3.12.12.
