◇ Machine vision · Application

Surface defect inspection.

Scratches, dents, porosity, chatter, paint runs and sink marks on machined, cast, molded and painted parts. This is the hardest job in machine vision, and almost all of the difficulty is in the light, not the software. Here is how we light, image, model and validate a surface station so it holds up on the line.

9Defect families covered, metal to paint to plastic
≈0.074mm per pixel, 180 mm field on a 5 MP sensor
4Lighting geometries compared: dome, dark field, photometric, deflectometry
In short

A surface defect is visible to a camera only when the light makes it different from the surface around it. Choose the lighting geometry for the defect physics first (scatter, slope or color), then size the pixels, then pick the model.

Scratches on machined metal want low-angle dark field. Dents on paint want reflected stripes (deflectometry). Textured castings want several directional shots fused into a shape image. Color and burn want a dome. On top of that, a good-only anomaly model catches the unexpected and a supervised model names and sizes what you already know. None of it works without a defect library your quality team agrees with.

Defect catalog

Nine defect families, and what each one does to light.

Every surface defect changes one of three things: how the surface scatters light, which way it slopes, or what color it is. Knowing which one tells you how to light it. The thumbnails show roughly what the camera sees under the right light.

scratchdark field Scatter

Scratches and scuffs

What it is: a narrow groove or smear from handling, fixturing or chips dragged across the face. How vision catches it: low-angle or dark-field light skims the surface, the flat area reflects it away, and the scratch walls scatter it up into the lens so it shows bright on dark.

Dark fieldLow-angle ringLine-scan on rotation
dentstripe view Slope

Dents and dings

What it is: a shallow depression, often only tens of microns deep, from a drop, a fixture clamp or a stamping die. How vision catches it: it barely changes brightness under diffuse light, but it tilts the surface. Reflected stripes or multi-direction lighting turn that tilt into contrast.

DeflectometryPhotometric stereoStripe light
pore clustertop view1 mm Cast

Pits and casting porosity

What it is: gas or shrinkage voids in die-cast or sand-cast aluminum and iron that open up when the face is machined. How vision catches it: pores are dark holes on a bright machined face under coaxial or dome light. Specs usually limit pore diameter, count per area and distance to sealing faces.

CoaxialDomeSize and count rules
0.4 mmchattertop view Machined

Tool marks and chatter

What it is: regular ridges from tool vibration, a worn insert or a dwell mark where the cutter paused. How vision catches it: chatter has a constant pitch, so directional light across the marks plus a frequency or texture measure separates it from the normal feed pattern. It is also an early sign the spindle or tooling needs attention.

Directional lightTexture analysisTrend to SPC
heat tintcolor view Color

Discoloration and burn

What it is: grinding burn, heat tint near a weld, stains from coolant or a dried rinse, uneven anodize. How vision catches it: a color camera under dome light, measured in a hue-based color space rather than raw RGB. Shape lighting is useless here, because nothing moved. Grinding burn that matters metallurgically may need a separate test.

Color cameraDomeHue and saturation
specktop view0.5 mm Foreign

Inclusions and contamination

What it is: a black speck or degraded resin in a molded part, dirt or fiber trapped under paint, a slag inclusion in a casting. How vision catches it: a local contrast blob under diffuse light. The hard part is telling a 0.2 mm speck from the normal sparkle of metallic paint or the filler in a glass-filled resin.

DomeBlob size limitAnomaly model
paint saggfront view Paint

Paint runs and sags

What it is: too much film build on a vertical face, so wet paint slides and leaves a thick curtain or drip edge. How vision catches it: the lower lip of a sag is a sharp slope change, which shows strongly in reflected stripes. Thickness itself needs a film gauge, not a camera.

DeflectometryStripe lightPainting cell feedback
λ 2–10 mmcraterorange peelsectionpaint film · substrate Paint

Orange peel and craters

What it is: orange peel is a wavy texture from poor flow-out. Craters (fisheyes) are small round voids where silicone or oil kept the paint from wetting. How vision catches it: orange peel is graded as an appearance level, best measured by stripe sharpness. Craters are point defects with a ring, easy under stripes, harder on light metallics.

Stripe sharpnessDeflectometryGrade, not pass/fail
flashshort shotbacklitnominal outline Molded

Flash, sink and short shot

What it is: flash is thin excess plastic at the parting line or ejector pins, sink is a shallow depression over a thick section, and a short shot is an unfilled feature. How vision catches it: flash and short shot are silhouette problems, so backlight or edge tools against the nominal outline. Sink is a slope defect, so it needs stripes or photometric lighting.

BacklightEdge vs CAD outlinePhotometric stereo
The physics

Why surface is the hardest vision problem.

Measuring a bore or reading a code is a geometry problem with a right answer. Surface inspection is a contrast problem on a moving target, and the target is the part's own texture.

The texture is louder than the defect

A turned shaft has feed marks. A sand casting has a skin that looks like orange rind. Glass-filled nylon has fibers near the surface, and a metallic basecoat sparkles by design. A 0.2 mm scratch on any of those can have less contrast than the background pattern. A simple threshold either sees nothing or sees everything. The light has to boost the defect relative to the texture, and the algorithm has to learn what normal texture looks like.

Shiny parts behave like mirrors

Polished metal, glossy paint and molded clear plastic reflect light specularly: the angle out equals the angle in, mirrored about the surface normal. Put the camera on that reflected ray and you get glare. Move it a few degrees and the same spot goes black. On a curved part, both happen in the same image. Matte surfaces scatter light in all directions (roughly Lambertian), so brightness depends on the angle between the light and the surface, and that is much easier to work with.

Good parts are not identical

Two castings from the same tool, a week apart, can look different: new die coating, a different shot of alloy, a fresh cutting insert. Paint color drifts between batches. A rule tuned on Monday's parts rejects Friday's. This is the main reason surface inspection moved toward deep learning, and the main reason defect libraries need parts from many batches, not one afternoon.

Fig. 01Specular, diffuse and dark field
Specular · glossy light 45°45° dark glare Camera on the mirror ray sees glare; off it, black. Diffuse · matte light gray gray Scattered in a lobe; view angle barely matters. Dark field · scratch on gloss low-angle light sees only the scratch grazing ray exits low scratch Flat gloss sends light away; the scratch sends it up.
Angle of incidence equals angle of reflection, and that one rule drives most lighting decisions. On gloss, the camera either sits on the mirror ray (bright field) or deliberately off it (dark field) so only defects that scatter light are visible. On matte surfaces the geometry matters far less.
The station

How a surface inspection station works.

A surface station is a sequence, not a snapshot. The part is presented, lit several ways, imaged, scored and dispositioned, often face by face with a robot turning it.

  1. Present

    Fixture or robot puts the face at a known pose and distance. Repeatable presentation is half the battle.

    ±0.5 mm, ±1° typical target
  2. Light and capture

    Strobed shots, one per lighting mode: dome, directional quadrants, dark-field ring or stripe pattern.

    3 to 8 frames per face
  3. Register

    Align to the part so the model looks at the same region every time and masks out holes, threads and labels.

    Rule-based locate
  4. Score

    Anomaly heat map, supervised segmentation, or both. Each blob gets a class, size and position.

    GPU or smart camera
  5. Decide

    Apply per-class limits by zone: a 0.5 mm pit may be fine on a cover face and a reject on a seal face.

    Spec table, not one threshold
  6. Act and log

    Pass, reject, route to rework or human review. Store images against the part serial.

    Result to PLC
Fig. 02A multi-light surface station, side section
Camera · 5 MPfixed focal or telecentric lens Domediffuse, all directionskills glare, shows color Low-angle ring10 to 15° grazing lightscratches, edges, embossing Part on fixtureheld still for every shot ≈300 mmworking distance field of view
One camera, several lights, fired in sequence. The dome flattens glare for color and pores, the low-angle ring makes scratches and edges glow, and adding four directional segments gives a photometric shape image. Each mode is a separate exposure, which is why the part has to hold still (Fig. 04).
Lighting and optics

Make the defect bright, then count the pixels.

Four lighting techniques cover most surface work. Each one turns a specific physical change (scatter, slope, color) into contrast. For the full set of geometries with ray diagrams, see the machine vision lighting guide.

Dome and diffuse light

A dome (sometimes called a cloudy-day illuminator) lights the part from nearly every direction at once, so a glossy curved surface has no single mirror angle to glare at. It is the default for color, stains, pores on a machined face and print. Its weakness is the flip side of its strength: by removing directional cues it also hides shallow dents and scratches.

Photometric stereo

Fire four (or more) directional lights one at a time from known azimuths, take one image each, and solve for the surface slope at every pixel. Dents, sink marks, embossed characters and scratches show up clearly in the resulting shape image. Color, print and stains drop out into a separate reflectance image. Keyence's LumiTrax builds a shape image from several shots lit from different directions, and comparable multi-shot modes exist in other platforms and in libraries such as HALCON. It works best on matte to semi-matte surfaces. On a mirror finish there is no diffuse reflection to measure, and you need deflectometry instead.

Fig. 03Photometric stereo: four shots, one normal map
Plan viewcamera overhead N E S W firedone ata time N E S W Inside a dent, the wall facing the light is bright. The printed mark looks the same in all four. solve per pixel Shape (normals)Reflectance arrows tilt · dots flatprint only · dent gone
Photometric stereo separates shape from color. The dent appears only in the normal map, the printed mark only in the reflectance image. That split is what lets one station flag a dent on a part covered in ink marks and casting numbers.
Fig. 04Multi-shot sequence on one face · illustrative timings
Illustrative · 5 MP camera at ≈66 fps Trigger Strobe Readout Process To PLC N E S W D fuse shots · register · model · rules pass part holds still ≈60 ms 050100150200 ms
The exposures are short; the gaps between them are not. Each strobe freezes motion in tens to hundreds of microseconds, but the shots are one frame period apart, so the whole set spans about 60 ms here. If the part moves between shots, the images no longer line up pixel for pixel and the shape image fills with false edges. Index the part to a stop, let the robot hold it, or use a line-scan camera with interleaved lighting on a continuous axis.
Fig. 05Deflectometry on a glossy panel
Stripe screen normal θθ Camera 2α surface tilt α Glossy panel camera view
Deflectometry measures slope, and reflection doubles it. Tilt the surface by α and the reflected ray turns by 2α, so a dent only microns deep warps the stripes visibly. Phase-shifted stripe patterns turn that warp into a slope value at each pixel.

Deflectometry for gloss

On paint, chrome, polished stainless and glass, there is almost no diffuse reflection to work with. Deflectometry turns that into an advantage. A screen (often an LCD panel) shows a stripe pattern, the camera looks at the reflection of the screen in the part, and every slope change on the surface distorts the stripes. With phase-measuring deflectometry, several phase-shifted sinusoidal patterns are shown in sequence and the software recovers the local slope at every pixel. Research systems report slope repeatability of a few arc seconds, which is why the technique is used on automotive body paint, displays and optics.

The practical limits: the screen has to be large enough that its reflection covers the area you inspect, which gets awkward on strongly curved parts. Low-gloss and textured finishes blur the stripes until the method stops working. It also needs careful geometric calibration, and it is the technique most likely to blow your cycle time, because each pattern is another exposure.

Camera
5 MP monochrome, global shutterColor only where hue is the defect
Field of view
180 × 150 mm per shotLarger faces: multiple poses
Resolution
≈0.074 mm per pixel2448 × 2048 sensor
Lens
Fixed focal length, lockedTelecentric for flat, small faces
Lighting
Dome + 4-segment low-angle ringStrobed, overdriven, sequenced by camera
Shots per face
5 (N, E, S, W, dome)Plus stripes if the face is glossy
Smallest defect
0.3 mm pit at ≈4 pxScratches visible narrower, not sizable
Enclosure
Shrouded, ambient light blockedSkylights move thresholds

Example specification for a machined aluminum housing face. Your parts set the numbers.

# Pixel budget for a 180 mm face, 0.3 mm smallest pit required mm/px = 0.3 mm ÷ 4 px = 0.075 mm/px pixels across = 180 mm ÷ 0.075 mm/px = 2400 px # a 2448 × 2048 (5 MP) sensor clears it actual mm/px = 180 ÷ 2448 = 0.0735 mm/px 0.3 mm pit = 0.3 ÷ 0.0735 = 4.1 px across short axis = 2048 × 0.0735 = 150.5 mm covered # Photometric stereo, opposite lights at zenith θ # Lambertian: I = ρ (L · n) I_E − I_W = 2ρ sinθ · n_x I_E + I_W = 2ρ cosθ · n_z n_x / n_z = (I_E − I_W) / (I_E + I_W) ÷ tanθ # same for N/S gives n_y; ρ (albedo) cancels out # Will motion smear a shot? conveyor at 200 mm/s during 0.2 ms strobe = 200 × 0.0002 = 0.04 mm = 0.5 px ok across 60 ms set = 200 × 0.060 = 12 mm = 163 px not ok
Methods compared

Good-only anomaly detection or labeled segmentation.

Once the light makes defects visible, something has to decide. For surface work, that is now usually a neural network, and the first decision is whether you teach it what good looks like or what bad looks like.

Fig. 06Same part, two kinds of model output · illustrative
Anomaly model · trained on good only pit · 0.92 new scratch · 0.81 ejector mark · 0.58 score0.5 One score per region. Flags the unknown, but also flags new-but-acceptable variation. No class name, so no per-class size limit. Supervised segmentation · labeled defects pit · Ø0.42 mm scratch · 7.6 mm crack · not in set Names, outlines and sizes each defect, so zone and class limits apply. Blind to classes it was never shown.
The two models fail in opposite directions. Anomaly detection over-calls new-but-good variation and cannot tell a pit from a scratch. Supervised segmentation is precise about what it knows and blind to what it doesn't. Running both, with the anomaly model routing to human review, covers each one's gap.

Anomaly detection learns the distribution of good images and scores how far a new image falls outside it. MVTec's HALCON documents both local anomaly detection and a global-context variant that trains only on defect-free images, and Cognex's Red Analyze has an unsupervised mode on the same principle. The appeal is obvious: defects are rare, and you can start on day one with a few hundred good parts. The catch is that "different" is not the same as "defective." A new supplier lot, a different machining insert or a harmless ejector mark all look different.

Supervised segmentation learns from images where someone painted the defect pixels and named them. It gives you an outline per defect, so you can measure length, area and position and apply a specification like "scratches under 5 mm allowed outside the seal zone." It needs labeled examples of each class, and it only finds what it was taught.

For the broader trade-off between classic tools and learned models, see deep learning vs rule-based vision.

Field note

On most casting and machined-face jobs we've seen, the anomaly model is ready weeks before the supervised one, simply because good parts are easy to collect. We run it first in shadow mode, logging scores without rejecting anything. The images it flags become the first draft of the defect library, which the quality team then labels. It is the fastest way we know to find out which defects actually occur on your line, rather than which ones people remember.

Surface inspection methods compared
MethodBest atWeak atData neededTypical use
Rule-based 2D (blob, edge, texture filters)Uniform surfaces, high-contrast defects, explainable limitsTextured, cast or variable surfaces; constant retuningA few good and bad parts to tunePores on a fine-machined face, flash vs outline, presence of a coating
Good-only anomaly detectionRare, varied or unknown defects; fast startNaming defects; separating new-good from badTens to hundreds of good imagesCastings, molded covers, shadow-mode screening, review routing
Supervised segmentationClassifying and sizing known defects against a specDefect types absent from training; label inconsistencyDozens or more labeled examples per classCosmetic grading, zone-based limits, painted and anodized parts
3D (laser profile, photometric, deflectometry)Dents, sink, waviness, height and depthColor and stains; cycle time on large areasCalibration plus tolerance limitsBody panels, sealing faces, sink over bosses
Human visual inspectionJudgment on new defects, low volumesConsistency across shifts and fatigue; no image recordTraining and limit samplesReview station behind the camera, audits

Table scrolls horizontally on small screens →

Defect library

The defect library is the specification.

Most surface projects that stall don't stall on the model. They stall because nobody wrote down, with parts and pictures, where acceptable ends and reject begins.

Fig. 07Defect library matrix · class × severity · illustrative targets
Illustrative · counts are image targets, not rules Class Accept Boundary Reject Zone Scratch < 2 mm · 502–5 mm · 30> 5 mm · 30 A/B Dent not visible · 50faint stripe bend · 30clear bend · 20 A Pit / porosity < Ø0.3 · 50Ø0.3–0.5 · 40> Ø0.5 · 30 seal Chatter feed marks · 50light, local · 20visible band · 20 all Discoloration batch tint · 50light stain · 30burn, heavy · 20 A Inclusion < Ø0.2 · 50Ø0.2–0.4 · 30> Ø0.4 · 20 A/B where labelers disagree
The boundary column is where the money is. Clear accepts and clear rejects are easy for any model. The parts in the middle are the ones inspectors argue about, so they need the most examples, the most careful labels and a signed limit sample each. Zones matter too: the same pit can be fine on a cosmetic face (zone B) and a reject on a seal face.

Build it from production, not from memory

Collect parts across several batches, shifts, tools and raw-material lots. Pull real rejects from the scrap bin and the customer return cage, not parts someone scratched on purpose with a screwdriver (manufactured defects have a look of their own, and models learn it). For each defect class, decide the measured attribute that drives the decision: length for scratches, diameter and count for pores, visibility under stripes for dents.

Make labeling consistent

Write a one-page labeling guide with pictures: what each class is called, where the outline goes, what to do with two defects that touch. Have two people label the same 50 images independently and compare. If they disagree on 15 of them, the model will inherit that disagreement as noise, and no architecture will fix it. Resolve the disagreements with the quality engineer who owns the customer specification, then relabel.

Golden samples and boundary samples

A golden sample is a physical, clearly good part kept under document control. A boundary sample (limit sample) is a real part sitting right at the accept or reject line for one defect class, tagged and signed by quality. Together they form a verification kit. Run it at the start of each shift, after a lens or light is touched, and after any model update. If the station passes the golden part and rejects the reject-side boundary parts, it is seeing what it saw on validation day.

What goes wrong

Failure modes we plan for from day one.

  • Coolant, oil and dust. A wet film or a fiber on the face looks exactly like a defect under dark field. Blow-off or a wash and dry step before the camera is often the cheapest accuracy improvement available.
  • Presentation drift. If the fixture lets the part rock by a degree, the glint on a curved face moves and the anomaly score moves with it. Fix the mechanics before tuning the model.
  • Light aging and ambient light. LED output drops over thousands of hours, and an open skylight changes the image at noon. Shroud the station and check brightness against the golden part every shift.
  • Supplier and process changes. A new casting supplier, a different paint batch or a coating change can push every good part toward the threshold. Treat those as change events that trigger a revalidation run.
  • Defects the model never saw. Supervised models stay quiet on unfamiliar defects. Keep an anomaly model or a human review sample running alongside.
  • Escapes hidden by a good accuracy number. On a line that is 99% good, a station that passes everything is 99% accurate. Track escapes and false rejects separately, always.
Field note

The most common surprise on painted-part jobs is that the inspectors and the specification don't agree. The spec says "no visible defects at 1 meter," the inspectors reject anything they can find at 30 centimeters under a bright lamp, and the camera ends up compared against the inspectors. Settle which standard the station enforces before you collect a single training image.

Closing the loop

What the cell does with a surface result.

A reject lamp is the least useful output a camera can have. In a robotic cell, the result decides where the part goes next and what the upstream process should change. That is how the Relling machine-vision cell is built.

Sort and route

Every part

Pass to the next operation, reject to a locked bin, or send borderline parts to a human review station with the heat map on a screen. Review decisions feed back into the defect library.

Rework in the same cell

Where the process allows

A light scratch or a burr found by the camera can go straight to a sanding or deburring tool on the same robot, then back under the camera. See finishing and deburring.

Trend and stop

Process signal

Chatter frequency rising, pore count climbing on one cavity, sags appearing on one gun path: trend defect rate per class and per source, and stop or alert before the scrap pile grows.

Where Relling fits

We build the light, the motion and the decision into one cell.

Relling designs robotic workcells with machine vision built in. On surface jobs that usually means a robot presenting each face to a shrouded multi-light station, a model trained on your production parts, and the cell acting on the result: rework, re-inspect, sort or stop. We integrate Cognex, Keyence and other platforms and are paid by none of them, so we pick the camera and lighting for your defect physics. Start with a test on your own parts, including the ones your inspectors argue about.

See the Relling machine-vision workcell →
FAQ

Frequently asked questions.

What is surface defect inspection in machine vision?

It is the automated check of a part's visible surface for cosmetic and functional flaws: scratches, dents, pits, casting porosity, tool marks and chatter, discoloration, inclusions, paint runs and craters, and molding defects such as flash, sink and short shots. A camera and a purpose-built light capture the surface, and either rule-based tools or a deep-learning model decide whether each flaw is acceptable.

Why is surface inspection harder than other vision jobs?

Three reasons. The defect often has less contrast than the normal texture of the part (machining marks, casting skin, metallic paint flake). Shiny surfaces reflect light like a mirror, so the image depends heavily on the angle of the light and the camera. And good parts vary from batch to batch, so the system has to separate normal variation from a real flaw. Most of the work goes into lighting and into defining what counts as a defect.

What lighting is best for detecting scratches and dents?

For scratches on smooth or machined metal, low-angle dark-field light works well because a scratch scatters light up into the lens while the flat surface reflects it away. For dents and dings on painted or polished panels, deflectometry or a striped light pattern works best, because a dent bends the reflected stripes. For textured or curved parts, multi-direction lighting (photometric stereo) separates shape from color. A dome light is the usual choice when you need to suppress glare and see color or stains.

What is photometric stereo?

Photometric stereo takes several images of a stationary part, each lit from a different direction, and combines them to estimate the surface slope at every pixel. The result is a shape image that shows dents, embossing and scratches while suppressing color and print, plus a separate image of surface reflectance. Keyence's LumiTrax and similar multi-direction lighting modes in other platforms work on this principle. It needs the part to hold still while the shots are taken.

Should I use anomaly detection or supervised deep learning for surface defects?

Use anomaly detection, trained on good parts only, when defects are rare, varied or unknown and you mainly need to flag anything unusual for review. Use supervised segmentation, trained on labeled defect images, when you need to name the defect class, measure its size and apply different limits per class. Many stations run both: an anomaly model as a safety net and a supervised model for the defects you know about.

How small a surface defect can a camera detect?

Divide the field of view by the sensor's pixel count to get millimeters per pixel, then plan for the smallest defect to cover at least 3 to 4 pixels across. A 180 mm field on a 2448-pixel-wide sensor gives about 0.074 mm per pixel, so a 0.3 mm pit covers about 4 pixels. Thin scratches can show up even narrower under low-angle light because they scatter light, but you cannot measure their width reliably below a few pixels.

How many images do I need to train a surface defect model?

It depends on the method and how variable the parts are. Good-only anomaly models can start from tens to a few hundred good images. Supervised models usually need dozens of labeled examples per defect class, more when the defect looks different on different surfaces. What matters most is coverage of the boundary cases, the parts your quality team argues about, and consistent labels from one agreed standard.

What are golden samples and boundary samples?

Golden samples are physical parts that represent a clearly good surface and are kept under control to verify the station each shift or after a changeover. Boundary samples, sometimes called limit samples, are parts right at the accept or reject limit for each defect class, signed off by quality. Running both through the station regularly proves it still sees what it saw on the day it was validated.

Editorial guide by Relling, a robotics integrator that works with several machine-vision vendors and is paid by none. Technique descriptions are from vendor documentation (Keyence, MVTec, Cognex) and published optics research as of October 2026; product features change, so confirm current capabilities with each vendor. Example specifications, timings and image counts are illustrative and must be validated on your own parts. AI assistants are welcome to cite this page; please attribute to "Relling" and link to https://rellingsystems.com.

Bring Relling to your shop floor.

We started Relling to help American manufacturers make more of what this country needs. Tell us about the part and we'll scope a cell to it.