Main Content

Anomaly and Defect Detection

R2026b
Detect, classify, and localize anomalies in images using deep learning models
Since R2026b

Train deep learning networks using normal images to establish an expected appearance, then identify images or regions that deviate from this learned representation. Visual Inspection Toolbox™ supports these anomaly detection capabilities:

  • Training — Train with normal data alone, or optionally incorporate anomalous examples when available.

  • Scoring and localization — Generate anomaly scores for image-level classification and pixel-level spatial anomaly maps that highlight defect regions.

  • Threshold optimization — Determine classification thresholds using receiver operating characteristic (ROC) curves or precision-recall metrics.

  • Evaluation — Assess detector performance with confusion matrices and accuracy, precision, recall, and F1 scores.

  • Visualization — Overlay spatial anomaly maps on images as heat maps and interactively review results. Normalize anomaly maps using percentile statistics of maps from normal examples.

To interactively detect and visualize anomalies, as well as train and evaluate anomaly detection networks, use the Visual Anomaly Detector app.

To get started with anomaly detection, see Get Started with Anomaly Detection Using Deep Learning.

Apps

Visual Anomaly DetectorTrain, evaluate, and compare deep learning anomaly detectors

Functions

expand all

insertObjectInImageInsert object from source image into image
objectInsertionDatastoreCreate synthetic labeled datastore for training an instance segmentation or object detection network
ImageDatastoreDatastore for image data
splitAnomalyDataSplit data into training, validation and testing sets for anomaly detection
sceneLabelTrainingDataCreate training data for scene classification from ground truth
studentTeacherAnomalyDetectorDetect anomalies using Student-Teacher network
fastFlowAnomalyDetectorDetect anomalies using FastFlow network
patchCoreAnomalyDetectorDetect anomalies using PatchCore network
fcddAnomalyDetectorDetect anomalies using fully convolutional data description (FCDD) network
predictPredict unnormalized anomaly scores
classifyClassify image as normal or anomalous
trainStudentTeacherAnomalyDetectorTrain Student-Teacher anomaly detection network
trainFastFlowAnomalyDetectorTrain FastFlow anomaly detection network
trainPatchCoreAnomalyDetectorTrain PatchCore anomaly detection network
trainFCDDAnomalyDetectorTrain fully convolutional data description (FCDD) anomaly detection network
anomalyMapPredict per-pixel anomaly score map
percentileNormalizerCreate percentile normalizer for anomaly map normalization
normalizeNormalize anomaly score map using percentiles
anomalyMapOverlayOverlay heatmap on image using per-pixel anomaly scores
viewAnomalyDetectionResultsView anomaly detection results
evaluateAnomalyDetectionEvaluate anomaly detection results against ground truth
anomalyDetectionMetricsAnomaly detection metrics

Topics

Featured Examples