/Connected-Component-Analysis---Image-processing

Repository for implementation of algorithms of connected component analysis in image processing

Primary LanguagePythonMIT LicenseMIT

Connected-Component-Analysis- Image-processing



Connected Component Analysis or Labelling enables us to detect different objects from a binary image. Once different objects have been detected, we can perform a number of operations on them: from counting the number of total objects to counting the number of objects that are similar, from finding out the biggest object of the bunch to finding out the smallest and from finding out the closest pair of objects to finding out the farthest etc

Algorithm


  • Process the image from left to right.
    • If the next pixel to process is 1
      • If only one from top or left is 1, copy its label.
      • If both top and left are one and have the same label, copy it.
      • If top and left they have different labels
        • Copy the smaller label
        • Update the equivalence table.
      • Otherwise, assign a new label.
    • Re-label with the smallest of equivalent labels

Example:

To illustrate connected components labeling, we start with a simple binary image containing some distinct artificial objects.

image

After scanning this image and labeling the distinct pixels classes with a different grayvalue, we obtain the labeled output image.

image

Note that this image was scaled, since the initial grayvalues (1 - 8) would all appear black on the screen. However, the pixels initially assigned to the lower classes (1 and 2) are still indiscernible from the background. If we assign a distinct color to each graylevel we obtain:

image