# MssimCalculator

Artifact: [androidx.media3:media3-test-utils](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/test/utils/MssimCalculator.java+class:androidx.media3.test.utils.MssimCalculator)

*** ** * ** ***

<br />

```
@UnstableApi
class MssimCalculator
```

<br />

*** ** * ** ***

Image comparison tool that calculates the Mean Structural Similarity (MSSIM) of two images, developed by Wang, Bovik, Sheikh, and Simoncelli.

MSSIM divides the image into windows, calculates SSIM of each, then returns the average.

See [the SSIM paper](https://ece.uwaterloo.ca/~z70wang/publications/ssim.pdf).

## Summary

| ### Public functions |
|---|---|
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/MssimCalculator#calculate(byte[],byte[],int,int)( referenceBuffer: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!, distortedBuffer: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!, width: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, height: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Calculates the Mean Structural Similarity (MSSIM) between two images with window skipping. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/MssimCalculator#calculate(byte[],byte[],int,int,boolean)( referenceBuffer: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!, distortedBuffer: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!, width: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, height: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, enableWindowSkipping: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html )` Calculates the Mean Structural Similarity (MSSIM) between two images. |

## Public functions

### calculate

```
java-static fun calculate(
    referenceBuffer: ByteArray<Byte>!,
    distortedBuffer: ByteArray<Byte>!,
    width: Int,
    height: Int
): Double
```

Calculates the Mean Structural Similarity (MSSIM) between two images with window skipping.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/MssimCalculator#calculate(byte[],byte[],int,int,boolean)` |   |

### calculate

```
java-static fun calculate(
    referenceBuffer: ByteArray<Byte>!,
    distortedBuffer: ByteArray<Byte>!,
    width: Int,
    height: Int,
    enableWindowSkipping: Boolean
): Double
```

Calculates the Mean Structural Similarity (MSSIM) between two images.

The images are split into a grid of windows. For each window, the structural similarity (SSIM) is calculated. The MSSIM returned from this method is the mean of these SSIM values. If window skipping is enabled, only every other row and column are considered, thereby only one in four windows are evaluated.

| Parameters |
|---|---|
| `referenceBuffer: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!` | The luma channel (Y) buffer of the reference image. |
| `distortedBuffer: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!` | The luma channel (Y) buffer of the distorted image. |
| `width: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The image width in pixels. |
| `height: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The image height in pixels. |
| `enableWindowSkipping: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether to skip every other row and column when evaluating windows for SSIM calculation. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html` | The MSSIM score between the input images. |