anomalyMap - Predict per-pixel anomaly score map - MATLAB (original) (raw)

Predict per-pixel anomaly score map

Since R2022b

Syntax

Description

[map](#mw%5Fdd0bb087-96c3-4f1c-b1e8-8b55a5810023) = anomalyMap([detector](#mw%5F95501c3b-b876-4a75-9161-884c93e88732%5Fsep%5Fmw%5Ff0686b83-345a-47b2-8ed0-7c3d0dde776c),[I](#mw%5F40e277b7-722d-46de-9fdd-5c0420dc15f7)) creates an anomaly score map consisting of per-pixel anomaly scores predicted for test imageI.

Note

This functionality requires Deep Learning Toolbox™ and the Automated Visual Inspection Library for Computer Vision Toolbox™. You can install the Automated Visual Inspection Library for Computer Vision Toolbox from Add-On Explorer. For more information about installing add-ons, see Get and Manage Add-Ons.

example

[map](#mw%5Fdd0bb087-96c3-4f1c-b1e8-8b55a5810023) = anomalyMap([detector](#mw%5F95501c3b-b876-4a75-9161-884c93e88732%5Fsep%5Fmw%5Ff0686b83-345a-47b2-8ed0-7c3d0dde776c),[I](#mw%5F40e277b7-722d-46de-9fdd-5c0420dc15f7),ExecutionEnvironment=[executionEnvironment](#mw%5Ff3185825-0171-4382-98ba-773315010107)) also specifies the hardware resource on which to run the detector.

Examples

collapse all

Load a pretrained FCDD anomaly detector. This detector has been trained to classify the digit 8 as normal and all other digits as anomalies.

load("digit8AnomalyDetector.mat");

Load test images and corresponding labels, then convert the test images to a formatted dlarray with the format label "SSCB" for spatial-spatial-channel-batch. The data set consists of grayscale images of handwritten digits 0–9.

[Xtest,gtLabels] = digitTest4DArrayData;

Select a test image of the digit 9.

digitToTest = "9"; digitIdx = find(gtLabels==digitToTest,1); imTest = Xtest(:,:,:,digitIdx);

Predict the per-pixel anomaly scores for the test image.

map = anomalyMap(detector,imTest);

Display the anomaly map over the test image.

overlay = anomalyMapOverlay(imTest,map); imagesc(overlay) axis image off

Figure contains an axes object. The hidden axes object contains an object of type image.

Input Arguments

collapse all

Test image, specified in one of these formats:

Format Supported Detectors
_M_-by-_N_-by-3 numeric array representing a truecolor image. EfficientAD, FCDD, FastFlow, PatchCore
_M_-by-_N_-by-3-by-B numeric array representing a batch of B truecolor images. EfficientAD, FCDD, FastFlow, PatchCore
Formatted dlarray (Deep Learning Toolbox) object with two spatial dimensions and one channel dimension. You can specify multiple test images by including a batch dimension. EfficientAD, FCDD, FastFlow

FCDD anomaly detectors also support grayscale test images, with one color channel instead of three.

Hardware resource on which to run the detector, specified as"auto", "gpu", or "cpu". The table shows the valid hardware resource values.

Resource Action
"auto" Use a GPU if it is available. Otherwise, use the CPU.
"gpu" Use the GPU. To use a GPU, you must have Parallel Computing Toolbox™ and a CUDA® enabled NVIDIA® GPU. If a suitable GPU is not available, the function returns an error. For information about the supported compute capabilities, see GPU Computing Requirements (Parallel Computing Toolbox).
"cpu" Use the CPU.

Output Arguments

collapse all

Anomaly score map, returned in one of these formats:

The values in the map are unnormalized. Larger values indicate a greater chance of a pixel being an anomaly. To normalize an anomaly map, use the percentileNormalizer object.

Data Types: single

Extended Capabilities

expand all

Usage notes and limitations:

FCDD, FastFlow, PatchCore EfficientAD
The size of I must be fixed at code generation time.The executionEnvironment argument is not supported. The datastore data format of I is not supported.

Usage notes and limitations:

FCDD, FastFlow, PatchCore EfficientAD
The size of I must be fixed at code generation time.GPU code generation does not support gpuArray inputs.GPU code generation supports inputs that are defined as half-precision floating point data types. For more information, see half (GPU Coder).The executionEnvironment argument is not supported. The datastore data format of I is not supported.

Version History

Introduced in R2022b

expand all

anomalyMap now supports the generation of C code (requires MATLAB® Coder™) and optimized CUDA code (requires GPU Coder™).