---
title: 'Computer vision label inspection, tested on 500 synthetic labels'
description: >-
  We ran four computer vision label inspection checks on 500 synthetic labels.
  All caught missing and skewed labels; light caused the false rejects.
author: elroot_labs
date: '2026-11-18'
categories:
  - artificial-intelligence
---
Computer vision label inspection compares each pack's label with a reference image: is the label there, is it in the right place and straight, and is each printed field present and readable. We built a synthetic test set of 500 camera frames with known faults and ran four versions of a classical inspection over it. Every version caught all 50 missing, shifted, skewed and wrong labels. The failures came from the light: a fixed brightness threshold rejected all 50 good labels in dim light, and the normalised version that cured that rejected 29 of 50 good labels with glare on them. Everything here was drawn by our own script, so read the numbers as a test of check designs, not as accuracy on a real line.

## We drew 500 labels with known faults

The test script uses only numpy and Pillow, nothing downloaded. It draws grey-scale camera frames of a white label on a textured package, at a scale of 0.2 mm per pixel, so a frame covers 120 by 80 mm and the label is 60 by 36 mm. The label carries a made-up product name, a batch and expiry line, and a pattern of bars standing in for a barcode. The bars are not a real barcode, and nothing in this test reads text or decodes a barcode.

Every frame gets ordinary variation: the label lands within 1 mm of its place and within 1 degree of straight, the light level moves by up to a tenth either way, and the sensor adds noise. On top of that the script makes ten classes of 50 frames each:

- good labels;
- good labels in dim light, at about half the normal brightness;
- good labels with a glare spot on or near the label;
- label missing, label shifted 4 to 8 mm, label skewed 4 to 8 degrees;
- batch line missing, smudged by a dark blot, or faded to about a third of its normal contrast;
- the wrong label, with a different product name and bar pattern.

The specification is the same for every version: the label must be found, its centre must be within 2 mm of where it belongs, its angle within 2 degrees, and each printed region must match the reference label. Each version set its pass marks from 30 separate good labels in normal light, taking the worst value seen and allowing 20 per cent slack. That calibration step turns out to matter.

![Six synthetic camera frames from the label test: a good label, the same label in dim light and with glare, a smudged batch code, a faded batch code and a label skewed by several degrees.](/images/blog/elroot/figures/computer-vision-label-inspection-synthetic-frames.png)

## Four versions of the same check

All four versions find the label, measure its centre and angle from its outline, rotate and crop it to line up with the reference, and then compare the name, the batch line and the bars region by region. They differ in how they handle brightness.

1. Fixed threshold: anything brighter than a set grey level counts as label, and each printed region passes if its average pixel difference from the reference is small enough.
1. Automatic threshold and normalised match: the threshold comes from each frame's own brightness histogram (Otsu's method), and each region is compared by normalised correlation, which ignores overall brightness and contrast.
1. Version 2 plus a contrast check: the darkest print in each region must stand far enough below the paper.
1. Version 3 after flat-field correction: the label is divided by an estimate of the light falling on it before any comparison.

Before the results run, our own alignment had a bug. The script measured the label's centre from its bright pixels only, so the dark print pulled the centre about 4 pixels and the angle about 0.4 degrees off, and good labels scored 0.1 to 0.3 on the name and batch match, where 1 is a perfect match. Filling in the label's outline before measuring fixed it, and good labels then scored 0.95 or better. If a label check rejects good labels, look at the alignment before the thresholds.

## Every version caught the obvious faults

| Test set, 50 frames each | Version 1 | Version 2 | Version 3 | Version 4 |
| ------------------------ | --------- | --------- | --------- | --------- |
| Good label               | 0         | 0         | 0         | 0         |
| Good label, dim light    | 50        | 0         | 0         | 1         |
| Good label, glare        | 1         | 29        | 29        | 22        |
| Label missing            | 50        | 50        | 50        | 50        |
| Shifted 4-8 mm           | 50        | 50        | 50        | 50        |
| Skewed 4-8 degrees       | 50        | 50        | 50        | 50        |
| Batch code missing       | 50        | 50        | 50        | 50        |
| Batch code smudged       | 2         | 50        | 50        | 50        |
| Batch code faded         | 25        | 3         | 50        | 50        |
| Wrong label              | 50        | 50        | 50        | 50        |

The numbers are frames rejected. For the three rows of good labels, every rejection is a false reject; for the other seven rows, every frame that was not rejected is a missed defect.

Missing, shifted, skewed and wrong labels, and a missing batch line, were caught 50 times out of 50 by every version. Those faults change the outline of the label or a whole printed region, and simple geometry and template comparison see them easily. A system that only has to catch those can be very simple. The interesting rows are the other five.

## Dim light broke the fixed threshold

Version 1 rejected all 50 good labels in dim light, every one as "label not found". The dim label sat around grey level 120, below the fixed threshold of 180, so to the check there was no label at all. Version 2 picks its threshold from each frame's own histogram and passed all 50.

Version 1 also missed 48 of the 50 smudged batch codes. A blot 12 to 24 pixels across barely moves the average difference over the whole batch line, so the average stayed under the pass mark. The normalised match in versions 2 to 4 caught all 50, because a dark blot changes the pattern of the region even when it hardly changes the average.

## The fix for dim light made glare worse

Version 2 rejected 29 of 50 good labels with glare on them, against 1 for version 1. Normalised correlation compares the pattern of light and dark inside a region with the reference, and a glare spot adds a bright slope across the region that the reference does not have. Where the spot pushes the paper to full white, part of the difference between paper and print is lost as well. The rejections fell on the name (16) and the batch line (13).

Version 4 tried to undo the glare in software by dividing the label by an estimate of the light on it. That brought the false rejects down from 29 to 22, which is still 22 good packs off the line out of 50.

| Version                                     | Good labels rejected in dim light | Good labels rejected under glare | Faded batch codes missed |
| ------------------------------------------- | --------------------------------- | -------------------------------- | ------------------------ |
| 1, fixed threshold                          | 50                                | 1                                | 25                       |
| 2, automatic threshold and normalised match | 0                                 | 29                               | 47                       |
| 3, plus contrast check                      | 0                                 | 29                               | 0                        |
| 4, plus flat-field correction               | 1                                 | 22                               | 0                        |

![Bar chart from our synthetic computer vision label inspection test, out of 50 frames per class: a fixed threshold rejected all 50 good labels in dim light, the normalised match rejected 29 good labels under glare and missed 47 faded codes, and a contrast check cut the faded misses to 0.](/images/blog/elroot/figures/computer-vision-label-inspection-failures-by-version.png)

Each version traded one failure for another, and none of them handled glare well. On a real line glare comes from where the lights and the camera sit relative to a shiny label, so we would treat it as a lighting and camera problem first and test it with real labels under the real lights. A synthetic test cannot stand in for that, and it is the next test we would run.

## Normalised matching passed faded print until we checked contrast

Version 2 passed 47 of the 50 faded batch codes. Normalised correlation is built to ignore contrast, which is what made it robust to dim light, and a batch code printed at a third of its normal darkness has the same pattern as a good one. Version 3 adds a plain contrast check, how far the darkest print in each region sits below the paper, and caught all 50. Version 1 caught only 25, because its average difference sits close to its pass mark for faint print.

A brightness-proof comparison and a contrast check do different jobs, and a label check needs both. The first decides whether the right thing is printed; the second decides whether it was printed dark enough to read.

## What to ask before a label check goes on the line

Our [guide to computer vision quality inspection](/blog/computer-vision-quality-inspection) says to measure missed defects and false rejects separately. This test shows what that looks like for labels, and what to ask of any system, ours or a vendor's:

- Does the test set include good labels under every lighting condition the line sees, with false rejects counted per condition? Our pass marks came from good labels in normal light only, which is why dim light and glare broke them.
- Is there a sample of each defect type, and has each check been shown to fail on its defect? Version 2 looked finished until the faded set showed it passed 47 of 50.
- Does every rejection name its reason (position, angle, which field, contrast)? Operators can act on "batch line faded"; they cannot act on "fail".
- Were the alignment numbers checked on good labels before the thresholds were tuned? Our own alignment bug made good labels look like failures.
- Is the test set run again after any change to the lights, the camera position or the label design?

## What this test does not show

The frames are synthetic. Every label is flat, sharp and printed identically from one made-up design, and the light and noise follow simple formulas. Real labels wrinkle, sit on curved bottles, blur as the line moves and vary from one print run to the next. Nothing here reads text or decodes a barcode. The pass marks were set on synthetic good labels. The numbers show how four check designs behave on faults we put there on purpose; they are not accuracy figures for any real line, and a real line will add failures this test cannot produce.

## Frequently asked questions

**What does computer vision label inspection check?** At minimum that the label is present, placed and straight within tolerance, and that each printed field matches the reference and is dark enough to read. In our synthetic test, presence, position, angle, a missing batch line and the wrong label were caught 50 times out of 50 by all four check designs.

**Why does a label inspection system reject good labels?** In our test, almost always because of light. A fixed brightness threshold rejected all 50 good labels in dim light, and a brightness-independent match rejected 29 of 50 good labels under glare, because its pass marks were set on labels in normal light only.

**Can software fix glare in label inspection?** Only partly, in our test. Dividing out an estimate of the light brought false rejects under glare from 29 to 22 of 50. We would fix glare at the lights and the camera first, and test that with real labels.
