Main Content

Get Started with Visual Inspection

R2026b

Visual inspection is the process of examining manufactured parts, assemblies, or environments to identify defects, verify dimensions, and ensure compliance with quality standards. In industrial settings, visual inspection encompasses a range of tasks from detecting surface anomalies on production lines to measuring critical dimensions of machined components.

The Visual Inspection Toolbox™ provides algorithms and tools that enable you to automate visual inspection tasks such as:

  • Quality control and defect detection — Identify anomalous regions in images of manufactured parts using deep learning models trained primarily on defect-free reference images.

  • Dimensional metrology and tolerance verification — Measure distances, angles, and geometric features with sub-pixel accuracy using caliper and edge-fitting tools.

  • Automated counting and inventory — Count objects in images using exemplar-based deep learning models that require only a few sample patches.

  • Production line monitoring — Detect and localize objects using deep learning object detection models, with support for deployment to edge devices and hardware.

Visual Inspection Capabilities

This table summarizes the major visual inspection areas in the toolbox, with information on getting started and links to relevant functionality and examples.

Inspection CapabilityRepresentative ImageGet StartedSee Also

Anomaly Detection — Detect, classify, and localize defects in images using unsupervised deep learning models trained only on defect-free reference images.

Anomaly detection heatmap overlaid on a defective pill image, highlighting the chipped region

For an example that uses this image, see Localize Industrial Defects Using PatchCore Anomaly Detector.

To interactively detect, classify, and analyze anomalies such as industrial defects, use the Visual Anomaly Detector app. You can also use the app to train, fine-tune, and evaluate anomaly detection deep learning models.

You can also programmatically detect anomalies:

Measurement — Measure distances, angles, and circular features in images using interactive and programmatic precision tools with edge-snapping accuracy.

Caliper measurements on a PCB image showing distance values between component pads

For an example that uses this image, see Create an App to Measure Images Using Edge‑Snapping Metrology.

Shape Matching — Align inspection images to a reference using shape-based template matching. You can also detect and localize objects from a single template image without training data.

Shape matching results showing detected metal plate objects with class labels overlaid

For an example that uses this image, see Detect Industrial Parts Using Multi-Class Shape-Based Matching.

  • Create a shape model from a template image using shapemodel.

  • Search for the template in an inspection image using matchshape to recover object poses, consisting of translation, rotation, and scale.

  • Preview edge features with show to tune extraction parameters.

  • Use the recovered transformation to align measurements or annotate detections.

Object Detection — Detect and localize objects in images using YOLOX deep learning models, with support for generating synthetic training data.

YOLOX object detection results on a PCB showing detected missing holes with bounding boxes and labels

For an example that uses this image, see Detect Defects on Printed Circuit Boards Using YOLOX Network.

You can also interactively detect objects in images and analyze detection results using YOLOX by using the Object Detector Analyzer app.

Object Counting — Count objects in images using only a few sample patches without requiring per-object annotation, by using exemplar-based deep learning models.

Object counting result showing blueberries with a count of 47 displayed in the corner

For an example that uses this image, see Count Objects Using CounTR Model.

Representative Visual Inspection Procedure

A typical visual inspection procedure includes image acquisition and setup, inspection, and decision-making.

Flowchart for typical visual inspection procedure.

Image Acquisition and Setup

Acquire images from cameras or sensors and load them into the workspace. For an example of live image acquisition, see Detect Anomalies in Pills During Live Image Acquisition (Image Acquisition Toolbox). Use image datastores to manage large collections of inspection images and organize them into training, validation, and test sets for deep learning models. For more information on using datastores, see Datastores for Deep Learning (Deep Learning Toolbox).

Inspection

Perform the inspection task using one or more of the techniques described in Visual Inspection Capabilities. To select between various detection approaches based on your inspection goal and available data, see Select Detection Approach for Visual Inspection.

Decision Making and Results Communication

Evaluate inspection results against acceptance criteria to make pass or fail decisions. You can compare anomaly scores against optimized classification thresholds, verify that measured dimensions fall within tolerances, confirm that shape matching scores meet minimum confidence levels, or check that detected object counts match expected values. Assess overall system performance using confusion matrices, and metrics such as precision, recall, and F1 scores.

Communicate inspection results to automation systems for traceability or to trigger actions such as part rejection or line stoppage. Use OPC Unified Architecture (OPC UA) or other industrial communication protocols to send inspection outcomes to programmable logic controllers (PLCs). For more information, see Industrial Communication Toolbox™.

Deployment

Deploy trained models and inspection pipelines to production environments. Export models to the Open Neural Network Exchange (ONNX) format for integration with external inference frameworks. Generate optimized C or C++ code for CPU-based deployment, or CUDA® code for NVIDIA® GPUs. You can use MATLAB® Compiler™ to package complete inspection applications as standalone executables for end users who do not have MATLAB. For more information, see Deploy Visual Inspection Code, Models, and Applications.

See Also

Topics