Main Content


Predict per-pixel anomaly score map



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

    map = anomalyMap(detector,I,ExecutionEnvironment=executionEnvironment) also specifies the hardware resource on which to run the detector.


    This function requires the Computer Vision Toolbox™ Automated Visual Inspection Library. You can install the Computer Vision Toolbox Automated Visual Inspection Library from Add-On Explorer. For more information about installing add-ons, see Get and Manage Add-Ons. To run this function, you will require the Deep Learning Toolbox™.


    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. Therefore, specify the set of positive labels as the set of digits between 0 and 9, excluding 8.


    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,catLabels] = digitTest4DArrayData;

    Select a test image of the digit 9.

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

    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);
    axis image off

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

    Input Arguments

    collapse all

    FCDD anomaly detector, specified as a fcddAnomalyDetector object.

    Test image, specified in one of these formats:

    • M-by-N numeric matrix representing a grayscale image.

    • M-by-N-by-3 numeric array representing a truecolor image.

    • M-by-N-by-C-by-B numeric array representing a batch of images, where C is the number of color channels of the images.

    • Formatted dlarray (Deep Learning Toolbox) object with two spatial dimensions. You can specify multiple test images by including a batch dimension.

    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.

    Data Types: single

    Version History

    Introduced in R2022b