Clor inspection

How to find the best method for color inspection

Written by Martin Falk Jensen
Machine vision Quality control

The human eye is remarkable in many ways, not least in its ability to see and distinguish colors. Perhaps our innate abilities are one of the reasons why many people underestimate how difficult color inspection can be.

There are plenty of pitfalls to navigate if you want to create a robust machine vision system for automated color quality control.

In this article, we shed light on 3 of the classic challenges you need to address to succeed with color inspection. The article is based on our experience at JLI with specific inspection tasks where the key has been to identify and separate colors robustly.

Avoid reflections to measure the right light

Imagine looking at a red car on a summer's day, with sunlight reflecting off the lacquered surface.

Your brain knows it's red and that the bright areas are just reflections of sunlight in the paint. But a machine vision system will look at the colors in the image that the camera captures and won't perceive them as only red, even though the car is red.

At a certain angle, the light doesn't reach the red paint before it reflects off the surface and is picked up by the camera. This means it's not the car's color, but the color of the light source that the camera picks up - or a mixture of the two.

red carEnsuring you're measuring the right light is crucial to correctly identify colors. The key is to avoid direct reflection and instead position the camera in relation to the light source to measure the diffuse reflection, where the light enters the color of the item to be inspected before bouncing back.

We have experienced this specific challenge when inspecting stacks of food packaging, where we had to quality check that the correct packaging was used in the production - based on the colors on the thin rim of the packaging.

However, the glossy surface meant that all the colors almost looked the same because the color of the light from the light source became dominant.

Only by working with the positioning of the light source and camera in relation to the packaging it was possible to capture an image where the colors could be separated with high accuracy.

Accurate color inspection requires calibration of the light source

Colors are basically light in different wavelengths, and therefore the color of the light with which we observe an object also determines the color we perceive.

The sun is the ultimate light source, and the ability of light sources to reproduce colors is described by a so-called CRI (Color Rendering Index) value. The scale goes from 0-100, where 100 is natural light.

In other words, no two light sources are the same, and this is important to remember if you want a successful color inspection.

If you need to change the light source in your machine vision system at some point, you need to make sure that the system continues to detect colors in the same way as with the original light source.

You can do this by calibrating the system with a calibration item - a color palette where each color has a predetermined value. By calibrating the system against these fixed colors, you can calculate correction factors that ensure the system measures colors in a consistent way, even if the light source has changed slightly.

Color Inspection(1)

How to mathematically separate colors

Once you've got your lighting and camera under control so you can capture optimal images, the next challenge is to create calculations on the image so you can separate the colors with mathematical values.

The key here is to find the right color spaces to use for your calculations. Colors can be described in several ways, or with several different color spaces such as RGB, HSV, YCbCr, CMYK, and LAB.

RGB, where the color is described based on the values for red, green, and blue, is the natural starting point because this is what standard color cameras produce. But if you have, for example, a dark blue and a black, they will be close to each other in the color space, and it can be difficult to confidently separate them by calculating RGB values. In these cases, you can use the HSV color space, which looks at hue, saturation, and value.

Often an inspection task will be about separating colors, but it could also be that the task is to measure the absolute color to make sure that, for example, a toy has a very exact color. In these cases, you can make use of the three-dimensional LAB color space, which is designed to reproduce colors in the same way the eye will perceive them.

LAB color space-1Choosing the right color space or combination of color spaces is an important foundation for the calculations in the machine vision system. At JLI, we have developed a tool that makes it possible to quickly assess how close the colors are to each other in the different color spaces and thus assess how easy or difficult it will be to separate them with a machine vision system.

This is also a matter of adding tolerances to the color space that define which colors are acceptable - for example, where, in the color space, do we define a color as blue and when is it no longer "blue enough"? The tolerances can be added as two- or three-dimensional "islands" in the color space, which the machine vision system then uses to determine whether the colors are within or outside the tolerance.

Color inspection can be a challenging task  

Depending on the complexity of the task, color inspection can be a challenging discipline, and there are many considerations to be made to ensure that you measure the right color and develop an algorithm that can separate the colors and calculate consistently and robustly.

If your quality control includes many colors or colors that are similar, the optimizations described can be crucial to your success.

You are always welcome to reach out to us if you need advice on how to solve your next color inspection task.