Clustering/labeling B/W or true/false 3D image


Dear All,

Is there any functionality in Julia to label (divide into separate clusters) 3D binary (0 and 1 or true/false) images?

I could find two functions in the JuliaImages, but with the lack documentation i was unable to figure out if this is exactly what i need (most likely works only for 2D + it seems that seg below is in some special format):

  1. img_labeled = labels_map(seg)
  2. labels = segment_labels(seg)

Many thanks in advance for help!




If I understood you correctly you would like to perform connected component labeling on a 3D volume. If that is the case then the function you seek is label_components which is defined in the Images package.

The first parameter to the function is the multidimensional array that you would like to label, and the second parameter is a multidimensional array which specifies the connectivity between pixels. For example, in two dimensions 8-connectivity is specified by a 3 by 3 matrix, e.g. trues(3,3). In 3-dimensions, 26-connectivity is specified by a 3 by 3 by 3 matrix, e.g. trues(3,3,3).

The following code snippet will return a multidimensional matrix labels where every voxel is given the label 1 since all voxels in test_volume constitute a single connected component.

test_volume = ones(Int, 5, 5, 5)
labels =  label_components(test_volume , trues(3,3,3)) 


Hello Zygmunt,

Sorry for late reply - i somehow missed your answer here.
I actually did it basically exactly as you proposed here. But let it stay for future references.

Thank you very much!