Image segmentation is one of the key processes in machine vision applications for partitioning a digital image into a group of pixels. There are many interesting ways one can segment an image. Take a look at the below image of candies placed in a particular order to form a word. And, If a robot with vision were a task to count the number of candies by color, it would be important for it to understand the boundaries between the candies.

A direct thresholding to separate the foreground from its background will create overlapping candies making it hard for us to count them. Take a look the below grayscale image and the one after OTSU threshold.

Image in Grayscale

Image in Grayscale

Image for post

Image after Thresholding

As we can clearly see that its almost impossible for a robot to count the candies because there is no way for us to define the boundaries between the candies. I even tried a variant of watershed algorithm but because of the presence of bright coloured candies the thresholding always failed.

This led me to the only solution which is how even a human being would do this task. Let us make our robot color aware because Grayscale algorithms are clearly not useful here. The image we are dealing with here is an RGB image with millions of colors where each pixel is a set of Red, Green and Blue channel intensity ranging from 0–255. The colors R (Red), G (Green) and B (Blue) have a close color correlation level which makes it difficult to segment. The trick is to transform RGB to a different color space where the boundaries between the colors are well defined. For this experiment I will pick the CIE-Lab color space which closely resembles how humans see colors.

Image for post

#computer-vision #machine-vision

Machine Vision Recipes: Isolating a Color in an Image
1.35 GEEK