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.
| Parameter | Description |
|---|---|
| table | Specifies the input CAS table that contains the images to be searched. |
| queryImage | Specifies the path to the image that will be used as the search query. |
| casOut | Specifies the output CAS table to store the matching results, including coordinates and match scores. |
| methodOptions | Specifies the matching algorithm and its specific options. Use 'TEMPLATEMATCH' for exact pixel matching or 'DESCRIPTORMATCH' for feature-based matching. |
| threshold | Sets a minimum confidence level (from 0 to 1) to filter out low-quality matches. |
| highlight | If set to true, draws rectangles around the detected matches in the output images. |
| decode | If set to true, decodes the output images with highlights, making them directly viewable. |
| copyVars | A 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. |
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.
| 1 | PROC CAS; |
| 2 | image.loadImages / |
| 3 | path="/path/to/image/folder/" |
| 4 | casOut={name="images_to_search", caslib="casuser", replace=true}; |
| 5 | RUN; |
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.
| 1 | PROC 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}; |
| 7 | RUN; |
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.
| 1 | PROC 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}; |
| 11 | RUN; |