Main Content

anomalyMap

Predict per-pixel anomaly score map

Since R2022b

    Description

    map = anomalyMap(detector,I) creates an anomaly score map consisting of per-pixel anomaly scores predicted for test image I.

    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 = anomalyMap(detector,I,ExecutionEnvironment=executionEnvironment) 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

    Anomaly detector, specified as an efficientADAnomalyDetector object, an fcddAnomalyDetector object, a fastFlowAnomalyDetector object, or a patchCoreAnomalyDetector object.

    Test image, specified in one of these formats:

    FormatSupported 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:

    • M-by-N numeric matrix, when the test image I is a 2-D grayscale or truecolor image.

    • M-by-N-by-1-by-B numeric array representing a batch of images, when I is numeric array representing a batch of images.

    • Formatted dlarray (Deep Learning Toolbox) object, when I is a formatted dlarray object.

    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

    Version History

    Introduced in R2022b

    expand all