Skip to content

Episode 6, Exercise 3 labelling with connected components #38

@wangliyuan72

Description

@wangliyuan72

Brief description

Connected component labelling is a prevalent way to label pixels that could be identified as the same object. To perform such analysis, it is important to define 'connectivity' which pixels are considered direct neighbours of a pixel. I think neubias's page on connected component is great to use. It demonstrated 1 and 2 connectivity in both 2D and 3D.

From prior exercises, students now have binary images from different thresholding approaches. Briefly, with binary images as input, we use connected components analysis by defining connectivity, producing a label image with separated objects. The exercises use label function from skimage.measure. skimage.measure.label(label_image, background=None, return_num=False, connectivity=None)

Input:

2nd step:

  • we introduce the concept of connectivity as we need to define which pixels are considered direct neighbours of a pixel. Essentially, do we consider the diagonal pixels as part of the objection x (demo-ed below).
    labels_2D_conn1_image = label(binary_2D_subregion, connectivity=1)
    labels_2D_conn2_image = label(binary_2D_subregion, connectivity=2)
  • we can use matplotlib.pyplot.imshowto visualise them.
  • Probably worth mentioning that the label image contain objects (each has its own assigned integer).
1-connectivity     2-connectivity    
     [ ]           [ ]  [ ]  [ ]            
      |               \  |  /               
[ ]--[x]--[ ]      [ ]--[x]--[ ]      
      |               /  |  \            
     [ ]           [ ]  [ ]  [ ]

We can mention the following equivalent nomenclatures

  • 2D: 1 connectivity = 4 connectivity
  • 2D: 2 connectivity = 8 connectivity
  • 3D: 1 connectivity = 6 connectivity
  • 3D: 2 connectivity = 26 connectivity

3rd step:

  • to visualise label images by colour coding and overlaying raw data. [skimage.color.label2rgb](Probably worth mentioning that the label image contain objects (each has its own assigned integer).)
    image_label_overlay = label2rgb(labels_2D_conn1_image, image=raw_image, bg_label=0, kind='overlay')

4th step:

  • we can count the number of objects in the label image by len() of the resulting array of `numpy.unique(labels_2D_conn1_image)

Learning objective(s)

Covers Objective Labelling with Connected Components.

I think the first two objectives can be achieved by working on (segmented) binary images (2D or 3D) to identify objects by defining connectivity=1 or 2. Less connectivity, one will have more separation; more connectivity will result in more merging of objects.

with label2rgb function, Learners will be able to overlay colour coded labels over desired image (we can define this to be the original image).

Volunteer(s)

@terezbelinova @marcodallavecchia (Hi again, feel free to add any comments). Thanks
@wangliyuan72

Metadata

Metadata

Assignees

No one assigned

    Labels

    exercise-proposalProposed exercises for the new curriculum

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions