Machine vision / Article
Rule-based vs deep-learning vision: which one your defect needs
Use rule-based vision when the defect can be written as a number, and deep learning when it can only be recognised. A missing component, a 0.3 mm tolerance, a barcode, a position check: those are rules, and rules are cheaper, faster and easier to defend in an audit. A scratch that looks different on every part, a texture flaw, a defect class nobody has photographed yet: those are learned. This article gives you the decision table, the honest case for staying rule-based, and what to do when you do not have enough defect images to train anything.
The numbers at a glance
01 / The split
One is configured. The other is trained
Rule-based machine vision has been the industrial standard since the 1980s, and it works by comparing captured images against fixed parameters: dimensions, colour thresholds, edge profiles, template matches. You are the source of the criterion. That is its strength on a stable line, and, as one automotive comparison puts it, also its limit, because the moment production conditions change, a new lighting angle, a material variation, a new model on the same line, the rules break down and engineers rewrite parameters.
Deep learning inverts the relationship. Instead of being told to reject anything outside a 0.3 mm tolerance, the model is shown examples and learns which surface variation is acceptable and which scratch pattern is a defect. The academic framing is the same: rule-based methods depend on threshold segmentation, edge detection and morphological operations, and their performance is highly dependent on handcrafted feature design and parameter tuning, so fixed rules often fail to generalise when surface textures are complex or defect types diverse. Neither statement makes deep learning the default. It makes the defect the deciding factor.
02 / The decision table
Six axes that settle the argument
Run your defect down this list before anyone quotes you hardware. In most plants two or three rows point the same way, and that is your answer.
03 / The honest case
Where rule-based is still the right, cheaper call
It would be easy to sell you a neural network for every station. It would also be wrong. Rule-based vision remains the better engineering choice for presence and absence checks, dimensional gauging, position and orientation, fill level, label placement, and reading barcodes or fixed-font characters. In each of those the acceptance criterion already exists as a number in your drawing, so training a model to rediscover it adds cost, latency and one more thing to validate.
The trade guidance says the same in plainer terms: use deep learning for complex, variable tasks, and traditional methods for simpler, well-defined tasks including gauging and measuring, because they are inherently faster and rely on predefined rules requiring less computational power. If a rule-based tool holds your escape rate today, the honest recommendation is to keep it and spend the budget on the station that is actually leaking. Our breakdown of where AOI and manual inspection costs actually sit is the better place to start that argument.
04 / Where learning earns it
Defects you cannot write down
Deep learning earns its cost in four situations. Cosmetic and textural flaws on varied surfaces, where a scratch that matters and a cosmetic mark that does not look nearly identical to a threshold. Assemblies with many possible faults, where enumerating every failure mode is impractical. Rare or never-before-seen defects, where the training set will always be thin. And mixed-model lines, where appearance shifts between variants without the quality standard shifting with it.
The fourth case has a specific answer. Anomaly detection is trained on good images only, so the system learns the correct, fully assembled part and highlights any deviation, even a defect it has never seen before. That matters on assembly work where one unit is missing a spring, the next is missing a screw, and the next has a gasket seated wrongly. It also matters for over-rejection: a model can be trained to flag significant scratches while deliberately ignoring the minor cosmetic marks your customer accepts, which is the same false-call problem we cover in reducing AOI false calls without letting defects escape.
05 / On your parts
Trained on your defects, not a stock dataset
The reason most deep-learning inspection projects disappoint is not the architecture. It is that the model learned someone else's parts. A model trained on a public dataset carries a decision boundary drawn around another plant's tolerances, another plant's lighting, another plant's idea of acceptable. At CODETRACE machine vision and AOI, models are trained on your real defect images, captured under the imaging setup that will actually run in production, so the boundary sits where your quality standard sits.
That leaves the honest obstacle: you may not have enough defect images, because a good line does not produce many defects. This is where NVIDIA defect image generation for AOI does the work, expanding a thin set of real defect images into a training set broad enough to learn from without waiting months for failures to accumulate. CODETRACE is a member of the NVIDIA Inception program, and systems are deployed and tuned on-site from Shah Alam in Selangor and Batu Kawan in Penang.
06 / Where to start
Run both against the same defect
The decision is cheap to test and expensive to guess. Pull fifty good parts and every defective part you have kept, and try to write the acceptance criterion as a number. If you can, you have a rule-based job and you should buy the simpler machine. If three engineers write three different criteria, the defect is a recognition problem and a model is the correct tool. Then run whichever candidate you pick alongside your current check on live production, and measure escape rate and false-call rate together, because improving one at the cost of the other is not an improvement.
Most plants in the Klang Valley end up with both on the same line, and that is a good outcome rather than a compromise. Vision is also one station inside factory automation, so the inspection choice should be made with handling, rejection and traceability in the same conversation. If you want the groundwork first, our explainer on what AOI actually does across six inspection jobs maps which of those jobs are rules and which are learned.
Rules for what you can specify. Learning for what you can only recognise.
FAQ / Rule-based vs deep learning
Questions, answered.
01What is the difference between rule-based and deep-learning machine vision?
Rule-based vision runs fixed algorithms you configure yourself. You set the threshold, the edge criterion, the tolerance, and the system applies it identically to every part. Deep-learning vision is trained instead of configured. You show it labelled examples of good and defective parts, and a neural network learns the visual pattern that separates them. Rule-based needs a defect you can describe numerically. Deep learning needs a defect you can only recognise.
02When is rule-based machine vision still the better choice?
When the defect is geometric and repeatable. Presence and absence checks, dimensional gauging, position and alignment, barcode and fixed-font character reading, and any inspection tied to a numeric tolerance are all cheaper, faster and more auditable with rules. Rule-based systems also keep a structural speed advantage, because simple arithmetic over fixed image regions executes faster than neural network inference, and they need no defect image library to get started.
03How many defect images does a deep-learning vision model need?
Fewer than most buyers assume, but the number depends on how variable the defect is. Published surface-defect research has trained segmentation models with roughly 5 to 33 defective samples per fold and still measured usable detection. Anomaly-detection approaches go further and train on good parts only, which suits lines where the defect is rare or has never been photographed. Where real defect images are genuinely scarce, synthetic defect image generation can expand the training set.
04Can rule-based and deep-learning vision run on the same line?
Yes, and on most real lines they should. A common split has deep learning classify the part or find the cosmetic anomaly, then rule-based tools measure the specific feature and apply the numeric tolerance. Another has rule-based vision handle part localisation and robot guidance while a deep-learning model judges surface quality. You get deterministic measurement where you need an audit trail and learned judgement where the defect resists description.
05How does CODETRACE decide which approach a defect needs?
We start from your actual parts and your actual defect set, not from a product category. Models are trained on your real defect images so the decision boundary matches your tolerances rather than a generic template. Where defect images are too few, we use NVIDIA defect image generation to expand the training set for AOI. CODETRACE is a member of the NVIDIA Inception program and deploys and tunes systems on-site across Selangor and the Klang Valley.
Related / Machine vision