anomalyMap
Syntax
Description
creates an anomaly score map consisting of per-pixel anomaly scores predicted for test image
map
= anomalyMap(detector
,I
)I
.
Note
This functionality requires Deep Learning Toolbox™ and 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.
also specifies the hardware resource on which to run the detector.map
= anomalyMap(detector
,I
,ExecutionEnvironment=executionEnvironment
)
Examples
Display Anomaly Map Over Test Image
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
Input Arguments
detector
— Anomaly detector
fcddAnomalyDetector
object | fastFlowAnomalyDetector
object (since R2023a) | patchCoreAnomalyDetector
object (since R2023a)
Anomaly detector, specified as an fcddAnomalyDetector
object, a fastFlowAnomalyDetector
object, or a patchCoreAnomalyDetector
object.
I
— Test image
numeric array | formatted dlarray
object
Test image, specified in one of these formats:
Format | Supported Detectors |
---|---|
M-by-N-by-3 numeric array representing a truecolor image. | FCDD, FastFlow, PatchCore |
M-by-N-by-3-by-B numeric array representing a batch of B truecolor images. | FCDD, FastFlow, PatchCore |
Formatted | FCDD, FastFlow |
FCDD anomaly detectors also support grayscale test images, with one color channel instead of three.
executionEnvironment
— Hardware resource
"auto"
(default) | "gpu"
| "cpu"
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
map
— Anomaly score map
M-by-N numeric matrix | M-by-N-by-1-by-B numeric
array | formatted dlarray
object
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.
Data Types: single
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
The size of
I
must be fixed at code generation time.The
executionEnvironment
argument is not supported.
GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
Usage notes and limitations:
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.
Version History
Introduced in R2022bR2023a: Support for FastFlow and PatchCore anomaly detectors
You can now specify the detector
argument as a fastFlowAnomalyDetector
object or a patchCoreAnomalyDetector
object.
R2023a: Support for C and GPU code generation
anomalyMap
now supports the
generation of C code (requires MATLAB®
Coder™) and optimized CUDA code (requires GPU Coder™).
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)