Class PeakSignalToNoiseRatio
Implements the Peak Signal-to-Noise Ratio (PSNR) metric for texture/image comparison. PSNR (in dB) is derived from the mean squared error (MSE) between a reference and a test image and depends on the peak pixel value (e.g., 255 for 8‑bit images). PSNR is commonly used to evaluate the fidelity of compressed images/video: higher values generally indicate better quality. Typical PSNR values for lossy compression often fall in the 30–50 dB range, though this depends on content, bit depth, resolution, and viewing conditions. Distortions are more likely to be perceptible below ~30–35 dB, while values above ~40 dB are often considered high quality. PSNR is a simple, non-perceptual metric; for perceptual assessment it should be complemented with other measures such as SSIM or color-difference metrics (e.g. DeltaE).
Inherited Members
Namespace: UnityEngine.TestTools.Graphics
Assembly: UnityEngine.TestTools.Graphics.dll
Syntax
public class PeakSignalToNoiseRatio : TextureComparisonAlgorithm
Constructors
PeakSignalToNoiseRatio(ITextureComparisonSettings)
Initialized a new instance of the Peak Signal to Noise Ratio (PSNR) algorithm with the given threshold.
Declaration
public PeakSignalToNoiseRatio(ITextureComparisonSettings settings)
Parameters
| Type | Name | Description |
|---|---|---|
| ITextureComparisonSettings | settings | Ratio under which the test constraint fails |
Methods
Compare(Texture2D, Texture2D)
Compares two Texture2D and returns a Peak Signal to Noise Ratio.
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 Peak Signal To Noise Ratio. higher being better, 30 being the human perceptible threshold. |
Overrides
Compare(Texture2D[], Texture2D[])
Compares two arrays of textures using the Peak Signal to Noise Ratio (PSNR) 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 texture being evaluated |
Returns
| Type | Description |
|---|---|
| ITextureComparisonResult | The Peak Signal To Noise Ratio. higher being better, 30 being the human perceptible threshold. |
Overrides
CompareAsync(Texture2D, Texture2D)
Compares asynchronously two textures using the Peak Signal to Noise Ratio (PSNR) 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 PSNR comparison result |
Returns
| Type | Description |
|---|---|
| (object, bool) | A tuple containing the result and whether it passes the evaluation |