Article
Color correction matrix and its calculator with a color chart in ALTRON
One of the common complaints in packaging inspection is this: “White is right, gray is right, but the red of the logo comes out slightly orange in the image.” Here white balance no longer helps. What you need is The color correction matrix.. In this article we explain how to build it with a color chart and the ALTRON calculator and apply it to a color area-scan camera.
White balance only changes the gain of each channel separately so that neutral colors become neutral. But the color filters on the sensor are not exactly like the human eye. Part of the red light leaks into the green channel and part of the green into the blue. As a result, saturated colors, like that red of the logo, look slightly shifted.
The color correction matrix (CCM) compensates for this leakage. Each output channel is built from a combination of all three input channels, and a constant offset is added to it. That means twelve numbers: three coefficients and one offset for each channel.
- Place the standard 24-patch color chart under the same light you have on the production line.
- Before taking the photo, set the white balance correctly. The matrix does not replace white balance.
- Set the exposure so that the white patch of the chart is not saturated.
Open the Color Correction Calculator tool from the Tools menu:
- Open the chart photo 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, press Mirror Horizontal or Mirror Vertical.
- Press Extract from Color Checker. For each patch you see the observed color (Seen) and the expected color (Expected). The Weight column sets the importance of each patch in the calculation.
- Choose a model and press Calculate.
- Copy the twelve numbers with Copy Results.
In the graph editor, add the ColorCorrectionMatrix node after the Debayer node, because this node works on the RGB image. Then:
- In the node panel, turn on Enable.
- Press the Paste button so that the twelve copied numbers are placed into the matrix. If there are not exactly twelve numbers, the matrix does not change.
- To compare before and after, press Identity. The image passes through unchanged. Then load the matrix again.
The Use Lookup Table option is on from the start; leave it on. Instead of computing the matrix for every pixel, it uses a precomputed table and is much faster at high frame rates.
If different products are inspected under different lighting, build a separate matrix for each one. In the Preset Edit section, type a name and press Add. Update refreshes that same preset. When the product changes, simply select the appropriate matrix from the list.
If your color relationship is more complex than a single matrix, press Export Color Correction Template in the calculator. A file with the .cct extension is created. Load it into the ColorCorrectionTemplate node. This node is already present in the preset graph for the color area-scan camera. Each template is valid for only one pixel format.
If you have a line scan color camera, this template is the way to go. The ColorCorrectionMatrix node is only for area-scan cameras, but ColorCorrectionTemplate also works on line-scan cameras.
- Photographing the card under lighting other than the production line’s. The matrix is only correct for the lighting it was computed with.
- Saturated patches. If the white patch has hit the ceiling, its information is lost.
- Computing the matrix before white balance. Fix the white first, then compute the matrix.
If you want to read more about the theory behind the ColorChecker chart, see this Wikipedia article (English) is a good start.
See the colour models on the area scan cameras page. If you need help building a color matrix, let us know via contact page.