ApplicationsGuide

AI defect inspection for products with natural appearance variability

How many good images AI defect inspection needs when product appearance varies naturally, and when rule-based checks still win on natural variability.

LumaSpec Vision12 min read Share on LinkedIn

On this page 9 sections
  1. 01When does a variable product need AI inspection instead of rules?
  2. 02How many good images does the training set need?
  3. 03How do you capture training images so only the product varies?
  4. 04What resolution, lens and exposure does the field need?
    1. Worked example: a 300 mm face on a belt at 200 mm/s
  5. 05Which camera and light fit the line?
  6. 06How do you set the pass/fail threshold and prove it works?
  7. 07When does the AI approach fail?
  8. 08What do you check before ordering the parts?
  9. 09Questions

A wheel of cheese, a plank of walnut, a bolt of linen: no two good parts look alike. A fixed colour or brightness threshold then either floods the reject bin or waves real defects through, and the project stalls. This guide is for the engineer holding that product. It gives the decision rule for when anomaly detection beats rule-based checks, a training-set budget of roughly 200 defect-free images split across appearance variants, capture settings that keep the model honest, the optics math that sizes field, lens, exposure and f-number, and the validation test that proves the system before it runs. The worked line is a 300 mm part on a belt at 200 mm/s; substitute your own product.

When does a variable product need AI inspection instead of rules?

Go to anomaly detection when your defect definition is deviation from good appearance — mold on a rind, a crack in grain, a stain on fabric — and no single threshold separates good from bad; a rule that already catches 95% of your filed defects means rules should stay.

List what a rule could measure: mean colour in a region, blob area, edge count, texture energy. If those features catch 95% of the defects your quality team has filed, stay with rules — they are cheaper, deterministic and debuggable in an afternoon. AI vs rule-based smart camera inspection: how to choose walks that decision in detail.

Anomaly detection earns its keep when the defect is defined by deviation from good appearance. A crack that hides in wood grain, a mold fleck on a rind whose colour runs cream to ochre inside one batch, a stain on heather-grey fabric: each looks exactly like some legitimate good part under any single threshold. The model trains on good images only, learns the range the product itself spans, and scores how far a new image sits outside that range.

Two conditions must hold. The camera side has to be frozen — same lens, distance, light and exposure on every image — and the product's good range has to appear in training, across batches, ripening stages or grades. For grading whole parts by appearance rather than finding local defects, classify irregular objects by appearance reliably covers the sorting variant of the same problem.

How many good images does the training set need?

Budget about 200 defect-free images for a product with three to six natural appearance variants — roughly 40 to 60 images per variant — and hold 100 good and 50 defect images back to set the threshold.

The budget scales with variety, not with megapixels: a uniform product trains on about 100 good images, while four appearance variants want 4 × 50 = 200. Below roughly 40 images per variant the model's boundary of good turns ragged and false rejects creep in; past about 60 per variant the gain flattens. At one part per second, 200 captures are three and a half minutes of belt time — the work is covering every stage and batch, not pressing the shutter.

Split the capture: most images train the model, and the held-out images prove it. Defect images do not exist on a new line yet; use the first week's manually rejected parts, or plant defect patches onto good captures as stand-ins until real rejects arrive.

Keep each appearance variant — ripening stage, recipe, grade — as its own class rather than one mixed good pile: training anomaly detection across multiple product classes shows the class layout, and anomaly detection custom dataset training: fix folder and mask errors clears the folder mistakes that break a first run.

training images = appearance variants × 40–60 holdout: 100 good + 50 defect images, never trained on

How do you capture training images so only the product varies?

Freeze everything the camera controls — lens, working distance, exposure and light drive — so the only thing that varies across your 200 training images is the product itself.

Four settings do the freezing:

Shoot across at least three production batches, and include borderline good parts — the slight blotch a human inspector passes — because they teach the model where good ends.

What resolution, lens and exposure does the field need?

Size the pixels to the defect: a spot must span at least 3 pixels, so a 1 mm mold spot needs 0.33 mm/px or finer, and a 320 mm field then needs about 970 pixels across.

Three pixels across a defect is the detection floor; six to ten is where texture-based judgment gets comfortable and false calls fall. From the smallest defect you must catch, divide its size by 3 for the coarsest ground sample distance, then divide field width by that for the pixel count: 320 mm ÷ 0.33 mm/px ≈ 970 px. Any modern sensor clears the floor, so the real choice is how much texture detail you want.

Worked example: a 300 mm face on a belt at 200 mm/s

  1. Field. A 300 mm part with 6% margin gives a 320 mm field.
  2. Sampling. 4000 pixels across → GSD = 320 mm ÷ 4000 px = 0.08 mm/px; a 1 mm mold spot spans 1 ÷ 0.08 = 12.5 px.
  3. Magnification. 4000 px over a 7.4 mm sensor width (the 1/1.7" class) → m = 7.4 ÷ 320 = 0.023.
  4. Lens. With m = 0.023 and a 12 mm lens: WD = f × (1 + m) ÷ m = 12 × 1.023 ÷ 0.023 ≈ 530 mm. Check: m = 12 ÷ (530 − 12) = 0.0232 → FOV = 7.4 ÷ 0.0232 ≈ 319 mm, on target.
  5. Exposure. Blur ≤ 1 px = 0.08 mm at 200 mm/s → t = 0.08 ÷ 200 = 0.0004 s = 0.4 ms. Strobe the light; a 12.5 px spot survives a little blur, but 0.4 ms keeps edges crisp for the model.
  6. f-number. The face is flat and belt wander is ±8 mm, so depth of field must cover about 16 mm total. With λ = 0.00055 mm and (1 + m)² ÷ m² = 1.047 ÷ 0.000534 ≈ 1960: f/5.6 gives 2 × 5.6 × 0.00055 × 1960 ≈ 12 mm — too tight; f/8 gives ≈ 17 mm — covered. Set f/8 and let the strobe repay the light loss.
  7. Diffraction check. Airy diameter = 2.44 × 0.00055 × 8 ≈ 0.0107 mm ≈ 6 px at a 1.85 µm pitch — fine against a 12.5 px target. Do not stop past f/11, where the blur circle reaches about 8 px.
m = sensor width / field of view f = WD × m / (1 + m) GSD = FOV / pixels across exposure ≤ GSD / belt speed DOF ≈ 2 · N · λ · (1 + m)² / m²
How sensor width, working distance and field of view set the focal length Rays from the edges of the sensor pass through the lens and spread to the edges of the field of view. The ratio of sensor width to field of view is the magnification m.CameraField of view (FOV)Working distance (WD)≈ fsensor width slensm = s / FOVf = WD × m / (1 + m)
How sensor width, working distance and field of view set the focal length. Rays from the edges of the sensor pass through the lens and spread to the edges of the field of view. The ratio of sensor width to field of view is the magnification m.
Lens focal length, field of view and working distance
Units
Solve for
Focal length
– mm
Field of view
– mm
Working distance
– mm
Magnification
– x
Angle of view
– °
Pixel on the part
– mm

Thin-lens model: m = sensor width / field of view, f = WD × m / (1 + m). Accurate to a few percent above about 150 mm; check the lens's minimum object distance.

Find lenses with this focal length Open the full calculator

Run your own numbers through the depth-of-field calculator once the height wander is known. The decision for this line: 12 mm lens, 530 mm working distance, f/8, 0.4 ms strobed exposure, one 12 MP colour camera.

Which camera and light fit the line?

Put a 12 MP colour area scan camera over a diffused white bar light and stream to a PC or vision controller; choose a smart camera only where one measurable feature already does the job.

For the worked line, the sampling decision lands on 4000 × 3000 colour pixels at 30 fps, which area scan cameras reach in one frame at the working distance above. The 12 MP USB3 area scan camera resolves exactly that:

Area scan cameras12 MP USB3 area scan camera, IMX226, 1/1.7" rolling shutter, 30 fps, 4000 × 3000 resolution (LS-CMR-0166)LS-CMR-0166
Sensor format
1/1.7"
Interface
USB3
Resolution
12 MP
Shutter
Rolling
$560.00View partBuild a system with it

When subtle discoloration drives false calls, one sensor step pays for itself. The 20 MP colour GigE camera pairs a 1" sensor with a C-mount. At a 320 mm field, a 20 MP IMX183-class sensor resolves about 0.06 mm/px, so a 1 mm spot spans 17 px.

Where the check stays genuinely simple — one colour fraction, one blob area on a small part — keep the decision on the device. The smart cameras range runs inspection on the device without a PC, and the 1.6 MP smart camera integrates a 16 mm lens with white polarized light at 60 fps over GigE:

Smart cameras & vision sensors1.6 MP smart camera, 60 fps, 16 mm lens, white light (polarized, transparent light) (LS-SMC-0063)LS-SMC-0063
Interface
GigE
Resolution
Up to 3 MP
$1,110.00View part

Anomaly detection at 12 MP streams to a PC or a vision controller beside the belt; smart cameras run the single-feature checks at the station itself.

Under the lens, the 372 x 28 mm diffused white bar light spreads an even white field on 24 V:

Bar lightsBar light, 372 x 28 mm, White (LS-BAR-1276)LS-BAR-1276
Size
200-400 mm
Type
Diffused
Voltage
24 V
$439.00View partBuild a system with it

Size the lit length to the field — a 320 mm field wants roughly 400 mm of lit bar so the corners stay bright. On moist or glazed parts add cross-polarization: polarizing film on the bar at 90° to a polarizer on the lens strips the sheen, and the model trains on texture instead of reflections; cross polarization machine vision: reduce surface glare shows the filter layout. The bar lights category splits standard, diffused and high-luminance types for exactly this choice, and the light finder filters by size and colour.

How do you set the pass/fail threshold and prove it works?

Set the anomaly threshold on images the model never trained on — 100 good and 50 defect holdouts — and place it where false rejects read 2% or less while the catch rate holds 95% or better.

The holdout size is measurement resolution, not bureaucracy. Two misses in 100 good images is the 2% false-reject reading, and two misses in 50 defect images reads 96% catch; a 30-image set can only ever quote 1 in 30 ≈ 3.3%, fine for a lab verdict, short of a customer promise. Anomaly detection metric configuration: align task and metrics matches the metric to the task, and ONNX anomaly detection inference: from maps to pass/fail carries the score map through to the pass/fail output your PLC consumes.

After startup, log the good-image score distribution per batch. A slow rise in good scores means something in the imaging chain or the product has drifted — lighting, lens, a new supplier's material — and it shows up days before it becomes false rejects. Biscuit crack detection: turn line results into decisions shows how to turn those line results into decisions an operator acts on.

When does the AI approach fail?

Anomaly detection fails when good changes faster than you can retrain: a new recipe every few weeks, daylight reaching the field, or a question that is dimensional rather than visual has no fixed image set behind it.

The three regular failures:

  • Good changes faster than training. A recipe or grade change every few weeks never lets the 200-image budget settle; fall back to rules on the features that do exist, or constrain the process visually first.
  • Ambient light reaches the field. Daylight swings colour temperature by thousands of kelvin across a shift, and the model reads weather as product drift. Enclose the station or shield the field.
  • The question is dimensional. Diameter, thickness, height, a missing component: these are measurements, not appearance deviations, and belong to rules or a 3D setup.

Unstable presentation fails a texture model too: hand-placed or swinging parts show geometry noise before surface texture. Fix presentation before the model. None of these apply to the worked line — fixed geometry, enclosed light, appearance-only defects — which is why anomaly detection is the right tool there.

What do you check before ordering the parts?

Run five checks with your own part before you order anything: smallest defect size, field with margin, exposure at your belt speed, depth of field against height wander, and a lighting trial over 20 parts from two batches.

  • Sampling: smallest defect ÷ 3 px = coarsest GSD; the camera resolution calculator turns it into a pixel count.
  • Field: part width + 6% margin; 320 mm on the worked 300 mm part.
  • Exposure: GSD ÷ belt speed, then strobe; 0.4 ms at 200 mm/s in the example.
  • Depth of field: total height wander against the DOF formula; f/8 covered 16 mm of wander at m = 0.023.
  • Lighting trial: 20 parts from two batches under the proposed bar; if sheen dominates the images, add the polarizer pair before you train anything.
  • Training budget: variants × 40–60 good images, plus 100 good and 50 defect holdouts.
  • Enclosure: no daylight path to the field.

Build the list against your own part, then size hardware in the camera configurator and the lighting step of the configurator; both feed one bill of materials. If the AI-versus-rules decision is still open on your product, send two batches of sample images through the contact page and the applications team will help you run the threshold test. More worked inspection lines sit on the applications topic page.

Questions

Can anomaly detection train without any defect images?

Yes for the model itself: it learns only from good images, so defect-free captures define normal. You still need labeled defect images afterwards to set the pass/fail threshold and measure the catch rate — 30 to 50 of them. Until real rejects exist, plant defect patches onto good captures as stand-ins, then swap in the first production week's manual rejects.

How many pixels do I need to see a 1 mm defect?

Three pixels across the defect is the working floor, so 1 mm needs 0.33 mm/px or finer. A 320 mm field then needs about 970 pixels across, which every modern sensor clears. A 12 MP camera at 0.08 mm/px shows a 1 mm spot as 12.5 pixels — enough texture detail to keep false calls low.

Where should the anomaly-detection model run?

On a PC or a vision controller beside the line for 12 MP texture work: the camera streams, the model scores, the PLC receives pass/fail. Smart cameras keep single-feature checks on the device, which is enough when one colour or blob rule already separates good from bad. Size the compute for your frame rate and tile count, not for the camera's resolution.

What lighting suits moist, glazed or waxy variable surfaces?

Diffused white light with cross-polarization: a polarizing film on the bar light at 90 degrees to a polarizer on the lens strips the specular sheen, so the model trains on texture and colour instead of reflections. Keep white for colour-true grading, drive the bar from a constant-current controller, and strobe during the exposure window so brightness holds from batch to batch.

How often does a variable-product model need retraining?

Plan a review per recipe or season: shoot 20 to 30 images of each new good appearance, add them to the training set, and re-run the holdout before the threshold moves. If appearance changes weekly, the 200-image budget never settles — that is the signal to fall back to rule-based checks on the features that do exist.