AI defect detection uses deep learning models trained on images of good and defective parts to find surface defects such as scratches, dents, cracks, pits and contamination, locate them, classify them by type and, with segmentation, measure their size so the reject decision follows the drawing. It outperforms rule-based vision on irregular defects and textured or variable surfaces, provided the lighting makes the defect visible in the first place.
This article is part of our guide to industrial AI. Here we go deeper on surface defect detection and classification: the defect types, the lighting that reveals them, the model choices, how to turn a detection into a reject decision, and how to measure performance.
Common surface defects and how to reveal them
| Defect | Looks like | Lighting that usually reveals it |
|---|---|---|
| Scratches | Thin lines that scatter light | Dark-field or low-angle lighting |
| Dents and dings | Local shape change | Low-angle, structured light or 3D |
| Cracks | Fine dark or bright lines, often branching | High resolution, dark-field or backlight on thin parts |
| Pits and porosity | Small holes or voids | Diffuse dome or coaxial lighting |
| Contamination and stains | Spots of different color or reflectance | Diffuse lighting, sometimes color or UV |
| Burrs and flash | Extra material on edges | Backlight or low-angle lighting |
| Discoloration and coating defects | Shade or gloss changes | Diffuse lighting, polarization for glare |
Lighting is the single biggest factor in surface inspection. Shiny metal and glossy plastic often need polarization or diffuse dome lighting to suppress glare; see when to use polarization in machine vision. A defect the camera cannot see consistently cannot be learned by any model.
Model approaches for AI defect detection
| Approach | Output | Best for | Data needed |
|---|---|---|---|
| Image classification | Good/bad or defect class per image or region | Grading, sorting by defect type | Labeled images per class |
| Object detection | A box and class for each defect | Locating and counting defects | Boxes drawn around defects |
| Segmentation | A pixel mask for each defect | Measuring defect size and area for reject limits | Defects outlined pixel by pixel |
| Anomaly detection | An anomaly score and heatmap | Rare or unknown defects, few bad samples | Mostly good parts |
Many systems combine two: an anomaly model as a safety net for anything unusual, and a classifier or segmentation model for the known defect types. See AI anomaly detection for how anomaly models and their thresholds work.
The defect detection pipeline, step by step
- Image acquisition. Trigger the camera as the part arrives; strobe the lighting to freeze motion.
- Locate and align. Find the part and region of interest with rule-based tools so the model sees parts in a consistent position.
- Pre-process. Normalize brightness, crop to the inspected surface, mask areas that are not inspected.
- Inference. Run the trained model on an edge GPU or accelerator.
- Measure and decide. Convert each detected defect into a size and position, then apply the drawing or customer limits.
- Act and record. Signal the reject mechanism, save the image and result against the part serial number.
From detection to a reject decision: a worked example
Drawings and customer specifications usually allow some cosmetic flaws below a size limit. Segmentation lets the system apply that rule instead of rejecting every mark.
Suppose the camera resolution is 0.02 mm per pixel, so each pixel covers 0.02 × 0.02 = 0.0004 mm². A segmentation mask for a stain covers 180 pixels: 180 × 0.0004 = 0.072 mm². If the specification allows stains up to 0.1 mm² on that surface, the part passes; a 300-pixel stain (0.12 mm²) would be rejected. The AI finds and outlines the defect; the reject decision uses an explicit, auditable size limit.
| Mask size (pixels) | Area at 0.02 mm/px | Limit 0.1 mm² |
|---|---|---|
| 180 | 0.072 mm² | Pass |
| 250 | 0.100 mm² | Pass (at limit) |
| 300 | 0.120 mm² | Reject |
Training data and labeling
Collect good parts across lots, shifts and suppliers, plus real examples of every defect type, including borderline ones. Write a defect standard with accept and reject examples so labels are consistent; most disagreements between the model and inspectors trace back to inconsistent labels. Our article on how much training data AI visual inspection needs covers volumes, resolution and rare defects.
Measuring performance
- Recall (detection rate) per defect type: the share of real defects caught. Escapes are the inverse.
- False-reject rate: the share of good parts rejected. At 120 parts per minute over an 8-hour shift (57,600 parts), a 0.5% false-reject rate is 288 good parts.
- Confusion between classes: which defect types get mixed up, if you sort by type.
- Cycle time: image capture to reject signal must fit the time per part; at 120 parts per minute that is 0.5 s.
Report these on a held-out test set from real production, not on the training images, and repeat the measurement after any retraining.
Challenges and how to handle them
- Glare and reflections on shiny parts: diffuse or polarized lighting, multiple light angles.
- Natural texture that looks like defects: include plenty of good-part variation in training; use segmentation plus size limits.
- Rare defects: anomaly detection, scrap and returns as data sources, carefully used augmentation.
- Drift: monitor scores, review rejects, retrain with new examples.
- Speed: crop to the inspected area and size the edge hardware for the line rate.
For a system in operation, see the Sciotex benchtop surface defect detection system and the surface defect detection example.
Surface defects slipping through?
Sciotex designs and builds industrial AI systems for surface defect detection, with the lighting, models and reject logic tested on your parts first, designed, programmed, built and supported in the US since 1997.
Frequently asked questions
It is the use of deep learning models trained on images of good and defective parts to find, locate and classify defects automatically, often with a pixel mask that allows the defect to be measured against a size limit.
Scratches, dents, cracks, pits and porosity, contamination and stains, burrs, discoloration and coating defects, as long as the lighting and resolution make them visible in the image.
For irregular defects on textured or variable surfaces, usually yes. For measurable features such as dimensions and presence, rule-based machine vision is often faster and easier to validate. Many systems use both.
The best practice is to let the AI find and outline the defect, then convert it into a size and position and apply explicit limits from the drawing or customer specification.
On edge GPUs, inference typically fits within the time per part on production lines; the full budget includes image capture, transfer, inference and the reject signal, so the system is sized to the line rate.