Introduction to Image Processing — Part 5: Image Segmentation 1

Aids
The Startup
Published in
3 min readFeb 1, 2021
Photo by Rodion Kutsaiev from Pexels

In the previous post, we have discussed how we can detect all objects in an image. However, it is not always the case that we would like to extract all the objects in an image. Sometimes, we only want to get particular objects of interest. For the first part of this post, we will discuss three methods: Thresholding, Otsu’s Method, and Color Segmentation.

Thresholding

This method is a trial-and-error method to find the adequate threshold value to segment an image from the whole photo. [1] We have already done this in the previous post, where we binarize the image by selecting the right threshold value and use it on a grayscale image.

Figure 1. Result of Thresholding method

Otsu’s Method

In the thresholding method, we manually set the threshold value to 0.46. Otsu’s method gives us a way to automatically find the adequate threshold value to segment our object of interest. This method assumes that the image is composed of a background and a foreground and works by minimizing or maximizing the intra-class variance. [1]

Figure 2. Result of Otsu’s method

The threshold value output of the function is ~0.5209, and this is what we used to binarize our image. It can be observed that the one we created using the thresholding method has less noise. The main advantage of using Otsu’s method is that we don’t have to do trial-and-error to find the value, and we can clean the few noises using some of the methods discussed in the previous posts.

Color Segmentation

The methods above will work if we only have one object or if we are going to get all the objects in the image. But what if we only want to get all the strawberries in a picture of mixed fruits, as illustrated in the image below. Thresholding and Otsu’s methods won’t simply work in this scenario.

Figure 3. Fruits image

To solve this problem, we will be utilizing the image’s color properties. In this image, however, looking at the RGB channel would not suffice because other fruits are “red-ish” in color like the apples. With this, it would be more suitable to use the HSV color space.

Figure 4. HSV space of the Fruits image

From the HSV color space values, we select which ones we could use to create the mask that would segment our object on interest using specified threshold values. For this example, we would be utilizing the hue and saturation color spaces.

Figure 5. Result of Color segmentation

Voila! We have successfully segmented all the strawberries from the image. You can repeat the steps to segment other fruits. The main challenge here would be determining the right color channel or space and threshold values to use because they would be different for every fruit.

We have discussed in this post three methods of image segmentation. We will explore other methods in the next part.

References

[1] B. Borja. “Lecture 5 – Image Segmentation Part 1”. IIP 2020.

--

--

Aids
The Startup

Computer Forensic Noob | Aspiring Data Scientist |