Anomaly localization

Also known as: pixel-level anomaly detection

On this page 7

Anomaly localization is the task of determining where an anomaly is located inside an input, such as the pixels of a scratch on a product image or the time steps of a fault in a sensor signal, rather than only deciding whether the input is anomalous. In anomaly detection, it extends an image-level or sample-level anomaly score into a spatial or temporal anomaly map that highlights the abnormal region.

In visual inspection, the task is also called pixel-level anomaly detection or anomaly segmentation. Most methods are trained only on normal examples, because defects are rare and varied, so the model must learn what normal looks like and flag every region that deviates from it.

How anomaly localization produces an anomaly map

A localization model assigns an anomaly score to each location (pixel, image patch, time step or graph node) and arranges the scores into a map with the same layout as the input. The image-level decision is then usually derived from the map, for example as its maximum value or the mean of its highest scores.

The typical pipeline has three stages. A feature extractor, often a convolutional network or vision transformer pretrained on ImageNet, turns each patch into a descriptor. A normality model measures how far each descriptor lies from the descriptors of normal training data. Upsampling and smoothing, often with a Gaussian filter, convert the coarse patch scores into a map at input resolution.

The main families of localization methods differ in how they model normality, as the following comparison shows.

ApproachHow the map is computedRepresentative methods
Feature embedding distanceDistance of patch features to a memory of normal featuresPatchCore, SPADE
Distribution modelingMahalanobis distance to a Gaussian per patch positionPaDiM
Reconstruction errorDifference between input and its reconstructionAutoencoders, diffusion models
Knowledge distillationDisagreement between teacher and student networksStudent-teacher methods
Normalizing flowsLow likelihood of patch featuresFlow-based detectors
Synthetic anomaly trainingSegmentation network trained on artificial defectsDRAEM-style methods
Main approaches to anomaly localization

Localization beyond images

Localization applies to any structured input where a reader needs to know which part is abnormal. The unit being scored changes with the data type, but the goal of pointing to the responsible region stays the same.

Data typeUnit that is scoredTypical output
ImagesPixel or patchHeatmap or segmentation mask
VideoRegion within a frame and time intervalSpatio-temporal tube
Time seriesTime step or windowFlagged interval
Multivariate sensorsSensor channel and time windowRanked list of channels
GraphsNode, edge or subgraphHighlighted substructure
System logsLog line or event sequenceFlagged log segment
Units of localization by data type

Localization in multivariate data overlaps with anomaly explanation, which asks why a sample is unusual. The difference is one of emphasis: localization points to a region of the input, whereas explanation may also describe which features or relationships produced the high score.

Evaluating localization quality

Localization is evaluated against ground-truth masks or intervals annotated by experts. Benchmarks such as MVTec AD provide pixel-precise masks for defects on industrial objects and textures, and VisA offers similar annotations for more complex scenes.

Several metrics are reported because each rewards a different behavior, and the choice of metric can change method rankings.

MetricWhat it measuresKnown weakness
Pixel-level AUROCRanking of anomalous versus normal pixelsDominated by large defects and many normal pixels
AUPROOverlap per connected defect regionRequires an integration limit, often 30 percent false positive rate
Pixel-level APPrecision and recall over pixelsSensitive to class imbalance settings
Dice or IoU at a thresholdMask overlap after binarizationDepends on the chosen threshold
Common metrics for anomaly localization

The per-region overlap (PRO) metric gives each connected defect equal weight, so a small crack counts as much as a large stain. This is why AUPRO is preferred in industrial work, where small defects are often the most critical.

Practical deployment and thresholds

Deployment requires converting the continuous map into a binary decision and mask. Teams typically set the pixel threshold on a validation set of normal images plus a few labeled defects, choosing a value that keeps the false alarm rate acceptable for the production line.

Image resolution and patch size strongly affect results. Small defects can disappear when images are downscaled to 224 or 256 pixels, so inspection systems often tile high-resolution images or crop regions of interest. Memory-bank methods such as PatchCore use coreset subsampling to keep inference fast, often retaining around 1 to 10 percent of normal patch features.

Operators trust localization only when maps are stable and interpretable. Good practice includes overlaying the map on the original image, logging per-region scores for later audits and periodically refreshing the normal memory bank when materials, suppliers or lighting change. In regulated settings, the map serves as supporting evidence for a human decision, not as an automatic rejection without review.

Time-series and sensor systems follow the same logic with different units. A monitoring pipeline scores sliding windows per channel, merges adjacent flagged windows into intervals and reports the channels with the largest contribution, so that maintenance staff can go directly to the affected pump, valve or server instead of searching the whole installation.

Limitations and common mistakes

Localization maps are useful but imperfect evidence. They can be coarse, shifted or confused by legitimate variation in normal products.

  • Logical anomalies: a missing or misplaced component may look locally normal, so patch-based methods fail to localize it.
  • Blurry maps: upsampling coarse feature maps spreads scores beyond the true defect boundary.
  • Domain shift: changes in lighting, camera position or material batch create false hotspots.
  • Contaminated training data: unnoticed defects in the normal set teach the model to accept them.
  • Confusing localization with segmentation: supervised segmentation needs labeled defects, while anomaly localization works mostly without them.

The simple explanation

Saying that something is wrong is only half the job. You also want to know where the problem is. Anomaly localization shows the exact spot that looks unusual.

Picture a teacher checking a drawing against many correct examples. The teacher does not just say the drawing has a mistake. The teacher circles the wrong part. A localization model does the same with photos, sensor readings or logs. It paints a heat map where the bright areas mark what looks different from normal.

How it is used in practice

A manufacturer of aluminum smartphone housings inspects about 20,000 parts per shift with high-resolution cameras. Defects such as scratches, dents and coating spots are rare and vary widely, so collecting labeled examples of every defect type is impractical. The quality team trains a patch-based localization model on roughly 1,000 images of good housings only.

For each new part, the model produces an anomaly map, and any region above the validated threshold is outlined on the operator screen. Instead of reviewing whole images, inspectors look only at the highlighted areas, which cuts manual review time per flagged part substantially. The maps also reveal that most scratches cluster near one fixture contact point, leading engineers to redesign the fixture and reduce that defect type on the line.