image

matchImages

Description

The matchImages action finds occurrences of a query image within a larger set of images stored in a CAS table. This functionality is crucial for tasks such as locating specific objects, identifying duplicate or near-duplicate images, or searching for visual patterns. The action offers two primary matching strategies: 'TEMPLATEMATCH' for finding exact pixel patterns, and 'DESCRIPTORMATCH' for a more flexible feature-based search that is robust to changes in scale, rotation, and lighting.

proc cas; image.matchImages / table={caslib="string", name="table-name"} queryImage={path="string", caslib="string"} casOut={caslib="string", name="table-name", replace=true} methodOptions={method="DESCRIPTORMATCH" | "TEMPLATEMATCH", ...} threshold=0.5 highlight=false decode=false copyVars={"var1", "var2",...}; run;
Settings
ParameterDescription
tableSpecifies the input CAS table that contains the images to be searched.
queryImageSpecifies the path to the image that will be used as the search query.
casOutSpecifies the output CAS table to store the matching results, including coordinates and match scores.
methodOptionsSpecifies the matching algorithm and its specific options. Use 'TEMPLATEMATCH' for exact pixel matching or 'DESCRIPTORMATCH' for feature-based matching.
thresholdSets a minimum confidence level (from 0 to 1) to filter out low-quality matches.
highlightIf set to true, draws rectangles around the detected matches in the output images.
decodeIf set to true, decodes the output images with highlights, making them directly viewable.
copyVarsA list of variables to copy from the input table to the output table.
descType(Within methodOptions) Specifies the descriptor type for feature-based matching, such as 'ORB' or 'BRISK'.
thresholdRatio(Within methodOptions) Specifies the ratio for filtering weak matches when using descriptor-based methods.
Data Preparation View data prep sheet
Loading Images into a CAS Table

Before performing image matching, you must first load your image files into a distributed CAS table. The code below uses the `loadImages` action to recursively scan a directory, load all found images, and create a CAS table named 'images_to_search' in the 'casuser' caslib.

Copied!
1PROC CAS;
2 image.loadImages /
3 path="/path/to/image/folder/"
4 casOut={name="images_to_search", caslib="casuser", replace=true};
5RUN;

Examples

This example performs a basic search using the template matching method. It looks for occurrences of a small image, 'template.jpg', within the images in the 'images_to_search' table. This method is fast and efficient for finding exact, unscaled, and unrotated replicas of the template.

SAS® / CAS Code Code awaiting community validation
Copied!
1PROC CAS;
2 image.matchImages /
3 TABLE={name="images_to_search", caslib="casuser"}
4 queryImage={path="template.jpg", caslib="casuser"}
5 methodOptions={method="TEMPLATEMATCH"}
6 casOut={name="template_match_results", caslib="casuser", replace=true};
7RUN;
Result :
An output table named 'template_match_results' is created. It contains rows for each detected match, specifying the image identifier and the bounding box coordinates (x, y, width, height) where the template was found.

This example demonstrates a more robust search using the descriptor matching method with ORB features. It's designed to find objects that may vary in size and orientation. A match threshold of 0.6 is applied to ensure only high-confidence matches are reported. Additionally, the `highlight` and `decode` options are enabled to produce a new CAS table where the matched regions are visually marked with bounding boxes.

SAS® / CAS Code Code awaiting community validation
Copied!
1PROC CAS;
2 image.matchImages /
3 TABLE={name="images_to_search", caslib="casuser"}
4 queryImage={path="object_to_find.jpg", caslib="casuser"}
5 methodOptions={method="DESCRIPTORMATCH", descType="ORB", thresholdRatio=0.7}
6 threshold=0.6
7 highlight=true
8 decode=true
9 copyVars={"_id_", "_path_"}
10 casOut={name="descriptor_match_highlighted", caslib="casuser", replace=true};
11RUN;
Result :
A CAS table named 'descriptor_match_highlighted' is generated. It includes the copied variables `_id_` and `_path_`, along with a new `_image_` column containing the images with highlighted matches. Additional columns provide details for each match, such as `_Match_Score_` and bounding box coordinates, for further analysis.

FAQ

What is the purpose of the matchImages action?
How do I specify the image to be searched for?
Which table contains the images to be searched against?
What matching methods are available in the matchImages action?
How can I visually highlight the detected matches in the output images?
Is it possible to filter out low-confidence matches?
What is the 'descType' parameter used for?