image

compareImages

Description

The compareImages action compares images from a source table with images from a reference table. It supports two comparison methods: Peak Signal-to-Noise Ratio (PSNR) and Structural Similarity Index (SSIM). The results, including the comparison values, are stored in an output table. This action is useful for tasks like quality control, change detection, or finding duplicate images.

image.compareImages / casOut={...}, referenceImages={...}, sourceImages={...}, [copyVars={...}], [maximum=double], [method="PSNR" | "SSIM"], [minimum=double], [pairAll=boolean], [pairOnPath=boolean], [pairReferenceOn='variable-name'], [pairSourceOn='variable-name'], [separateChannels=boolean];
Settings
ParameterDescription
casOutSpecifies the output table to store the comparison results. This is a required parameter.
referenceImagesSpecifies the input table containing the reference images for comparison. This is a required parameter.
sourceImagesSpecifies the input table containing the source images to be compared. This is a required parameter.
copyVarsSpecifies a list of variables to copy from the input tables to the output table.
maximumSpecifies the maximum comparison value to report in the output. Default is the largest possible machine double.
methodSpecifies the comparison method. Can be 'PSNR' (Peak Signal-to-Noise Ratio) or 'SSIM' (Structural Similarity Index). Default is 'SSIM'.
minimumSpecifies the minimum comparison value to report in the output. Default is the negative of the largest possible machine double.
pairAllIf set to TRUE, compares every source image with every reference image. Default is FALSE.
pairOnPathIf set to TRUE, indicates that the pairing variables specified in `pairSourceOn` and `pairReferenceOn` are file paths. Default is TRUE.
pairReferenceOnSpecifies the variable in the reference table to use for pairing images. Default is '_path_'.
pairSourceOnSpecifies the variable in the source table to use for pairing images. Default is '_path_'.
separateChannelsIf set to TRUE, the comparison is performed on each color channel separately. Default is TRUE.
Data Preparation View data prep sheet
Data Creation: Loading Source and Reference Images

This example demonstrates how to load two sets of images (source and reference) from server paths into two distinct CAS tables, `source_images` and `reference_images`. These tables will then be used for comparison.

Copied!
1PROC CAS;
2 image.loadImages /
3 path='path/to/source/images'
4 casOut={name='source_images', caslib='casuser', replace=true};
5 image.loadImages /
6 path='path/to/reference/images'
7 casOut={name='reference_images', caslib='casuser', replace=true};
8RUN;

Examples

This example compares images between `source_images` and `reference_images` tables using the default Structural Similarity Index (SSIM) method. Images are paired based on their file paths.

SAS® / CAS Code Code awaiting community validation
Copied!
1PROC CAS;
2 image.compareImages /
3 sourceImages={TABLE={name='source_images', caslib='casuser'}}
4 referenceImages={TABLE={name='reference_images', caslib='casuser'}}
5 casOut={name='comparison_results', caslib='casuser', replace=true};
6RUN;
Result :
An output table named `comparison_results` is created in the `casuser` caslib, containing the SSIM scores for each paired image.

This example uses the Peak Signal-to-Noise Ratio (PSNR) method to compare images. It only reports results where the PSNR is between 20 and 50. The comparison is done on the grayscale versions of the images (by setting `separateChannels` to FALSE), and an additional variable `_id_` is copied to the output table.

SAS® / CAS Code Code awaiting community validation
Copied!
1PROC CAS;
2 image.compareImages /
3 sourceImages={TABLE={name='source_images', caslib='casuser'}}
4 referenceImages={TABLE={name='reference_images', caslib='casuser'}}
5 casOut={name='psnr_results', caslib='casuser', replace=true}
6 method='PSNR'
7 minimum=20
8 maximum=50
9 separateChannels=false
10 copyVars={'_id_'};
11RUN;
Result :
An output table named `psnr_results` is created. It contains the PSNR values between 20 and 50 for each image pair, along with the `_id_` variable from the source table.

This example demonstrates a many-to-many comparison by setting `pairAll` to TRUE. Every image in the `source_images` table is compared against every image in the `reference_images` table using the SSIM method.

SAS® / CAS Code Code awaiting community validation
Copied!
1PROC CAS;
2 image.compareImages /
3 sourceImages={TABLE={name='source_images', caslib='casuser'}}
4 referenceImages={TABLE={name='reference_images', caslib='casuser'}}
5 casOut={name='all_pairs_comparison', caslib='casuser', replace=true}
6 pairAll=true;
7RUN;
Result :
The `all_pairs_comparison` table is generated, containing SSIM scores for all possible combinations of source and reference images.

FAQ

What is the purpose of the `compareImages` action in SAS Viya?
What comparison methods are available in the `compareImages` action?
How can I specify the source and reference images for comparison?
What does the `pairAll` parameter do?
How can I control which comparison results are saved?
What is the function of the `casOut` parameter?
Is it possible to compare individual color channels of the images?
How does the action pair images for comparison if not all images are being compared against each other?
Can I transfer variables from the input tables to the output comparison table?