Article
Color correction matrix and its calculator with a color chart in ALTRON
One common complaint in packaging inspection goes like this: "White is right, gray is right, but the red in the logo comes out slightly orange." White balance can't help here. What you need is a color correction matrix.

Why isn't white balance enough?
White balance only changes the gain of each channel separately, so that neutral colors stay neutral. But the color filters on the sensor do not match the sensitivity curves of the human eye exactly. Some red light leaks into the green channel. Some green light reaches the blue channel, and so on. As a result, saturated colors, such as that red logo, look slightly shifted.
A color correction matrix (CCM) compensates for this leakage. In this matrix, each output channel is built from a combination of all three input channels, plus an offset.
A closer look at the ColorCorrectionMatrix plug-in
This plug-in works with both color line scan cameras and color area scan cameras. It applies a 3 × 4 matrix to every pixel:
- The first row produces the red output, the second row green and the third row blue.
- The first three columns are the coefficients for the R, G and B inputs, with values between -10 and 10. The numbers on the main diagonal are the gain of each channel itself.
- A negative coefficient off the diagonal reduces leakage from one channel into another and makes colors more saturated.
- The fourth column is a fixed offset for each channel, between -200 and 200.
The Identity button resets the matrix to identity, so the image passes through unchanged. Any number you change is applied immediately. The Set Matrix button is for when you want to send the matrix again explicitly.
The Use Lookup Table option is on by default. Instead of computing the matrix for each pixel, it uses a prebuilt table covering all 8-bit colors. At high rates this is much faster. In return, the table uses memory, and rebuilding it after each matrix change causes a short pause.
Where do the matrix numbers come from?
Guessing twelve numbers by trial and error is not a sensible approach. That is why we have a separate Color Correction Calculator tool, which you open from the Tools menu. With a standard 24-patch color chart, the workflow is:
- Capture an image of the color chart under the same light you use on the production line, and open it with Open Image.
- Press Align to Chart (4 pts) and click the four corner patches in this order: top-left, top-right, bottom-right and bottom-left. All 24 patches snap into place. If the chart is mirrored in the image, use Mirror Horizontal or Mirror Vertical.
- In the matrix section, press Extract from Color Checker to fill the table. For each patch you see the observed color (Seen) and the expected color (Expected). The Weight column shows how important that patch is.
- Choose a correction model and press Calculate.
- Copy the twelve numbers with Copy Results, then press Paste in the ColorCorrectionMatrix plug-in.
The Paste button expects exactly twelve numbers, separated by spaces and listed row by row. If the count is wrong, the matrix is left unchanged.
Which model should you choose?
The calculator offers several models. The simplest are 3×3 and 3×4 in gamma space. In the 3×4 model, the offset helps with dark colors. Two other models, 3×3 and 3×4 in linear light, first linearize the color and then apply the matrix. According to the tool itself, these models keep white correct and avoid overfitting. The second-order polynomial model gives the lowest error in gamma space, but it may overshoot on extreme colors such as white.
If your color relationship is more complex than a linear matrix, the Export Color Correction Template button creates a template file with the cct extension. Load this file with the ColorCorrectionTemplate plug-in. This plug-in works on both line scan and area scan cameras. Each template is valid for one pixel format only.
Common mistakes
- Photographing the chart under light other than the production line's. The matrix is only correct for the light it was calculated with.
- Saturated patches. If the chart's white patch is clipped at the top of the range, its information is lost. Fix the exposure first.
- Skipping white balance. A CCM does not replace white balance. Correct white first, then calculate the matrix.
A small trick
If different products are inspected under different lighting, build a separate matrix for each and save it by name in the Preset Edit section. Add creates a new preset and Update updates it. From then on, when the product changes, just pick the right matrix from the list.
If you want to read more about the theory behind the ColorChecker chart, see this Wikipedia article (English) is a good start.
You can compare our color cameras on the camera comparison page. If you need help building a color matrix, let us know via contact page.