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 |
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 |