I wonder if there is a function to group equal, connected elements of a 2D array like
a = np.array([[12,12,14,14,11,11],
[10,10,11,11,11,11],
[10,14,14,10,11,13],
[12,12,14,13,13,13]])
into an array this:
[[1, 1, 2 ,2, 3, 3],
[4, 4, 3, 3, 3, 3],
[4, 5, 5, 6, 3 ,7],
[8, 8, 5, 7, 7, 7]]
The rules for connection: an element [i, j] is connected to [i-1, j], [i+1, j], [i, j-1], and [i, j+1].
I found scipy.ndimage.measurements.label but the problem is that it just consider the array values as zero (background) and ones.
12,12in the first row is grouped as 1 but in the last row as 8