Blob Detection and Connected Components

Abel Joshua Cruzada
3 min readJan 27, 2021

Building on the Spatial Filtering and Morphological Operations from my last blog, traditional Image Processing techniques can be an important asset to improve our machine learning models. Directly using raw images as inputs to your model usually requires thousands of images to create a decent model. However, by enhancing our image, removing unnecessary noises, and capturing the regional properties of objects(i.e., perimeter, area) in our image, we can lessen the number of images we need to a hundred. I have already discussed image enhancements , spatial filtering, and morphological operations from my last two blogs. In this blog, I am going to talk about how we can detect objects in our images and get their regional properties through blob detection and connected components.

Blob Detection

Blobs are defined as bright objects in a dark background or vice versa. I am only going to discuss the three Blob Detection methods used to automatically detect blobs in an image:

  1. Laplacian of Gaussian — takes the Laplacian or second derivative of a gaussian smoothed image.
  2. Difference of Gaussian — takes the difference of the two gaussian smoothed image.
  3. Determinant of Hessian — Looks at the Hessian matrix of each scanning window.

From the figure below, we compare the three Blob Detection methods’ performance on a binarized image of multiple candies. The Laplacian of Gaussian is the most sensitive method. Although it is the slowest among the three, it can detect smaller blob sizes. The Difference of Gaussian performed the fastest although detected some candies twice. In comparison, the Determinant of Hessian detected some blobs without really a candy.

Fig 1. Different Blob Detection method comparison

Connected Components

Blob Detection methods have successfully proven their capability in detecting objects in the image. However, what if we want to detect objects with irregular shapes or only detect objects of a particular size only or classify the object based on its properties. We can look for the connected components in the image instead of circular objects.

Going back to the candy example, we cleaned the binarized image using erosion and dilation morphological operations in the figure below. In getting the connected components in our image, we can identify our objects of interest. However, upon taking a closer look at the labeled image, we can see that some objects are labeled as one since they are connected to one another. The caveat of this approach is it would heavily rely on the cleanliness of the image. Traditional Image Processing techniques such as Fourier transform, Sobel Filtering or Morphological operations can be used in cleaning the image.

Fig 2. Labeled Connected Components

Earlier I mentioned classifying the objects of interest in our image. To do so, we can use the region properties of the connected components in our image. For example, we want to classify each type of note for the given music sheet below.

Fig 3. Music Sheet

We first need to clean the images where only the notes would remain using Fourier Transform and Morphological operations. We can then use the labeled connected components’ region properties to classify the different types of notes. Each type of note has a different area property, which we can use to classify the note. However, what about the pitch of each note? We can identify each note’s location and pitch through each note’s centroid property and the stave coordinates in the image.

Fig 4. Classified Music Sheet

Even without machine learning, we can classify different objects through the use of region properties of each connected component in an image. We can also use these properties as features to train a machine learning model without requiring a big dataset.

Originally published at https://abeljoshuacruzada.wixsite.com on January 27, 2021.

--

--

Abel Joshua Cruzada

An aspiring Data Science leader who aims to empower society through data.