the entry 2 in the input is connected to 1, but 1 is not connected to 2. Examples -------- Create an image with some features, then label it using the default (cross-shaped) structuring element: >>> from scipy.ndimage import label, generate_binary_structure >>> import numpy as np >>> a = np.array([[0,0,1,1,0,0], ... [0,0,0,1,0,0], ... [1,1,0,0,1,0], ... [0,0,0,1,0,0]]) >>> labeled_array, num_features = label(a) Each of the 4 features are labeled with a different integer: >>> num_features 4 >>> labeled_array array([[0, 0, 1, 1, 0, 0], [0, 0, 0, 1, 0, 0], [2, 2, 0, 0, 3, 0], [0, 0, 0, 4, 0, 0]]) Generate a structuring element that will consider features connected even if they touch diagonally: >>> s = generate_binary_structure(2,2) or, >>> s = [[1,1,1], ... [1,1,1], ... [1,1,1]] Label the image using the new structuring element: >>> labeled_array, num_features = label(a, structure=s) Show the 2 labeled features (note that features 1, 3, and 4 from above are now considered a single feature): >>> num_features 2 >>> labeled_array array([[0, 0, 1, 1, 0, 0], [0, 0, 0, 1, 0, 0], [2, 2, 0, 0, 1, 0], [0, 0, 0, 1, 0, 0]]) References ---------- .. [1] James R. Weaver, "Centrosymmetric (cross-symmetric) matrices, their basic properties, eigenvalues, and eigenvectors." The American Mathematical Monthly 92.10 (1985): 711-717. ú