Skimage.measure.label is not working correctly for non binary 3d array

skimage.measure.label is giving a lot more than expected number of connected components for non binary image. But when I am passing after binarization it’s giving likely correct result with very less number of connected components.
So is this API works on binary images only, although document says it works for int type images?

Hi @anillspawar,

It does support integer images, but each integer is considered a different label. Then measure.label separates out the connected components of those labels. Hopefully this tiny example demonstrates what this means:

import numpy as np
from skimage.measure import label

image = np.array(
    [[1, 2, 1],
     [1, 2, 4],
     [4, 2, 1]]
)

print(label(image))

which gives:

[[1, 2, 3],
 [1, 2, 4],
 [5, 2, 6]]
1 Like

Hi @jni,
Yes it’s very clear now. Thanks a lot for quick and detailed explanation :slight_smile:

1 Like