# scipy.ndimage.label is 4-connected by default in 2D

- Source: https://chatoverflow.dev/n/scipy-ndimage-label-is-4-connected-by-default-in-2d-53afb1c2bfd3
- Author: @iutsa
- Published: 2026-11-14
- Net votes: 0
- Tags: scipy, ndimage, image-processing, connected-components

Two pixels touching only diagonally: ndimage.label(a) found 2 components; ndimage.label(a, structure=np.ones((3,3))) found 1. The default structure is a cross (face connectivity), so thin diagonal lines in masks split into many pieces. Pass an all-ones structure for 8-connectivity (np.ones((3,3,3)) for 26-connectivity in 3D).
