Class StructuralSimilarity
Implements the Structural Similarity Index Measure (SSIM) for texture/image comparison. SSIM is widely used in image quality assessment (including digital video). The SSIM index is computed over sliding Gaussian-weighted windows on the reference and test images, and the per-window results are averaged across the full image. The window size and Gaussian parameters can be configured via StructuralSimilaritySettings. A window size of 11 and a Gaussian σ of 1.0–1.5 are common defaults. The resulting value typically lies between 0 and 1, where 1 indicates identical images and values near 0 indicate very low structural similarity. Note: Extreme cases (e.g., constant black vs. constant white) usually yield SSIM near 0; exact 0 depends on implementation details and stabilizing constants.
Inherited Members
Namespace: UnityEngine.TestTools.Graphics
Assembly: UnityEngine.TestTools.Graphics.dll
Syntax
public class StructuralSimilarity : TextureComparisonAlgorithm
Constructors
StructuralSimilarity(ITextureComparisonSettings)
Initialized a new instance of the Structural Similarity Index Measure (SSIM) algorithm with the given threshold.
Declaration
public StructuralSimilarity(ITextureComparisonSettings settings)
Parameters
| Type | Name | Description |
|---|---|---|
| ITextureComparisonSettings | settings | Index measure under which the test constraint fails |
Methods
Compare(Texture2D, Texture2D)
Compares two Texture2D and returns a Structural Similarity Index Measure.
Declaration
public override ITextureComparisonResult Compare(Texture2D expected, Texture2D actual)
Parameters
| Type | Name | Description |
|---|---|---|
| Texture2D | expected |
|
| Texture2D | actual | The texture being evaluated |
Returns
| Type | Description |
|---|---|
| ITextureComparisonResult | The Structural Similarity Index Measure. higher being better, 1 being the same texture. |
Overrides
Compare(Texture2D[], Texture2D[])
Compares two arrays of textures using the Structural Similarity Index Measure (SSIM) algorithm. Both arrays need to have the same length and are compared by corresponding index.
Declaration
public override ITextureComparisonResult Compare(Texture2D[] expectedTextures, Texture2D[] actualTextures)
Parameters
| Type | Name | Description |
|---|---|---|
| Texture2D[] | expectedTextures | The reference textures |
| Texture2D[] | actualTextures | The textures being evaluated |
Returns
| Type | Description |
|---|---|
| ITextureComparisonResult | The Structural Similarity Index Measure; higher being better, 30 being the human perceptible threshold. |
Overrides
CompareAsync(Texture2D, Texture2D)
Asynchronously compares two textures using the Structural Similarity Index Measure (SSIM) algorithm.
Declaration
public override Task<ITextureComparisonResult> CompareAsync(Texture2D expected, Texture2D actual)
Parameters
| Type | Name | Description |
|---|---|---|
| Texture2D | expected | The reference image |
| Texture2D | actual | The texture being evaluated against the reference |
Returns
| Type | Description |
|---|---|
| Task<ITextureComparisonResult> | A task with a result |
Overrides
Exceptions
| Type | Condition |
|---|---|
| NotSupportedException | Async comparison is not supported for this algorithm |
DescribeActual(ITextureComparisonResult)
Describes the measured values of a comparison result produced by this algorithm, as named values for structured result reporting. The algorithm owns the keys. Returns null when the algorithm does not provide structured values (or the result is not one of its own); reporting then falls back to the result's ToString().
Declaration
public override IReadOnlyDictionary<string, object> DescribeActual(ITextureComparisonResult result)
Parameters
| Type | Name | Description |
|---|---|---|
| ITextureComparisonResult | result | The result of a comparison run by this algorithm. |
Returns
| Type | Description |
|---|---|
| IReadOnlyDictionary<string, object> | The measured values as named values, or null. |
Overrides
DescribeExpected()
Describes the thresholds this algorithm compares against, as named values for structured result reporting. The algorithm owns the keys. Returns null when the algorithm does not provide structured values; reporting then falls back to Description.
Declaration
public override IReadOnlyDictionary<string, object> DescribeExpected()
Returns
| Type | Description |
|---|---|
| IReadOnlyDictionary<string, object> | The configured thresholds as named values, or null. |
Overrides
Evaluate(ITextureComparisonResult)
Evaluates the comparison result against the defined threshold.
Declaration
public override (object, bool) Evaluate(ITextureComparisonResult result)
Parameters
| Type | Name | Description |
|---|---|---|
| ITextureComparisonResult | result | The SSIM comparison result |
Returns
| Type | Description |
|---|---|
| (object, bool) | A tuple containing the result and whether it passes the evaluation |