---
title: Universal Image Quality Index
description: Compute Universal Image Quality Index (UniversalImageQualityIndex).
canonical: >-
  https://lightning.ai/docs/torchmetrics/stable/image/universal_image_quality_index
---
# Universal Image Quality Index {#universal-image-quality-index}

## Module Interface {#module-interface}

### `class torchmetrics.image.UniversalImageQualityIndex(kernel_size=(11, 11), sigma=(1.5, 1.5), reduction='elementwise_mean', **kwargs)` {#torchmetrics.image.UniversalImageQualityIndex}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/image/uqi.py#L31-L170)

Compute Universal Image Quality Index ([UniversalImageQualityIndex](https://ieeexplore.ieee.org/abstract/document/995823)).

As input to `forward` and `update` the metric accepts the following input

*   `preds` ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")): Predictions from model of shape `(N,C,H,W)`
    
*   `target` ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")): Ground truth values of shape `(N,C,H,W)`
    

As output of forward and compute the metric returns the following output

*   `uiqi` ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")): if `reduction!='none'` returns float scalar tensor with average UIQI value over sample else returns tensor of shape `(N,)` with UIQI values per sample
    

Parameters:

*   **kernel\_size** ([`Sequence`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence "(in Python v3.15)")\[[`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")\]) – size of the gaussian kernel
    
*   **sigma** ([`Sequence`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence "(in Python v3.15)")\[[`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)")\]) – Standard deviation of the gaussian kernel
    
*   **reduction** ([`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal "(in Python v3.15)")\[`'elementwise_mean'`, `'sum'`, `'none'`, `None`\]) –
    
    a method to reduce metric score over labels.
    
    *   `'elementwise_mean'`: takes the mean (default)
        
    *   `'sum'`: takes the sum
        
    *   `'none'` or `None`: no reduction will be applied
        
    
*   **kwargs** ([`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")) – Additional keyword arguments, see [Advanced metric settings](/docs/torchmetrics/1.9.0/user-guide/overview.md#metric-kwargs) for more info.
    

Returns:

Tensor with UniversalImageQualityIndex score

Example

```python
>>> import torch
>>> from torchmetrics.image import UniversalImageQualityIndex
>>> preds = torch.rand([16, 1, 16, 16])
>>> target = preds * 0.75
>>> uqi = UniversalImageQualityIndex()
>>> uqi(preds, target)
tensor(0.9216)
```

#### `plot(val=None, ax=None)` {#torchmetrics.image.UniversalImageQualityIndex.plot}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/image/uqi.py#L126-L170)

Plot a single or multiple values from the metric.

Parameters:

*   **val** (`Union`\[[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)"), [`Sequence`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence "(in Python v3.15)")\[[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")\], [`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")\]) – Either a single result from calling metric.forward or metric.compute or a list of these results. If no value is provided, will automatically call metric.compute and plot that result.
    
*   **ax** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`Axes`](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.html#matplotlib.axes.Axes "(in Matplotlib v3.11.2)")\]) – An matplotlib axis object. If provided will add plot to that axis
    

Return type:

[`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple "(in Python v3.15)")\[[`Figure`](https://matplotlib.org/stable/api/_as_gen/matplotlib.figure.Figure.html#matplotlib.figure.Figure "(in Matplotlib v3.11.2)"), `Union`\[[`Axes`](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.html#matplotlib.axes.Axes "(in Matplotlib v3.11.2)"), [`ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.5)")\]\]

Returns:

Figure and Axes object

Raises:

[**ModuleNotFoundError**](https://docs.python.org/3/builtins/exceptions.html#ModuleNotFoundError "(in Python v3.15)") – If matplotlib is not installed

```python
>>> # Example plotting a single value
>>> import torch
>>> from torchmetrics.image import UniversalImageQualityIndex
>>> preds = torch.rand([16, 1, 16, 16])
>>> target = preds * 0.75
>>> metric = UniversalImageQualityIndex()
>>> metric.update(preds, target)
>>> fig_, ax_ = metric.plot()
```

[![../../\_images/universal\_image\_quality\_index-1.png](/docs/torchmetrics/1.9.0/static/_images/universal_image_quality_index-1.png)](/docs/torchmetrics/1.9.0/static/_images/universal_image_quality_index-1.png)

```python
>>> # Example plotting multiple values
>>> import torch
>>> from torchmetrics.image import UniversalImageQualityIndex
>>> preds = torch.rand([16, 1, 16, 16])
>>> target = preds * 0.75
>>> metric = UniversalImageQualityIndex()
>>> values = [ ]
>>> for _ in range(10):
...     values.append(metric(preds, target))
>>> fig_, ax_ = metric.plot(values)
```

[![../../\_images/universal\_image\_quality\_index-2.png](/docs/torchmetrics/1.9.0/static/_images/universal_image_quality_index-2.png)](/docs/torchmetrics/1.9.0/static/_images/universal_image_quality_index-2.png)

## Functional Interface {#functional-interface}

### `torchmetrics.functional.image.universal_image_quality_index(preds, target, kernel_size=(11, 11), sigma=(1.5, 1.5), reduction='elementwise_mean')` {#torchmetrics.functional.image.universal_image_quality_index}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/functional/image/uqi.py#L119-L171)

Universal Image Quality Index.

Parameters:

*   **preds** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – estimated image
    
*   **target** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – ground truth image
    
*   **kernel\_size** ([`Sequence`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence "(in Python v3.15)")\[[`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")\]) – size of the gaussian kernel
    
*   **sigma** ([`Sequence`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence "(in Python v3.15)")\[[`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)")\]) – Standard deviation of the gaussian kernel
    
*   **reduction** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal "(in Python v3.15)")\[`'elementwise_mean'`, `'sum'`, `'none'`\]\]) –
    
    a method to reduce metric score over labels.
    
    *   `'elementwise_mean'`: takes the mean (default)
        
    *   `'sum'`: takes the sum
        
    *   `'none'` or `None`: no reduction will be applied
        
    

Return type:

[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")

Returns:

Tensor with UniversalImageQualityIndex score

Raises:

*   [**TypeError**](https://docs.python.org/3/builtins/exceptions.html#TypeError "(in Python v3.15)") – If `preds` and `target` don’t have the same data type.
    
*   [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError "(in Python v3.15)") – If `preds` and `target` don’t have `BxCxHxW shape`.
    
*   [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError "(in Python v3.15)") – If the length of `kernel_size` or `sigma` is not `2`.
    
*   [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError "(in Python v3.15)") – If one of the elements of `kernel_size` is not an `odd positive number`.
    
*   [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError "(in Python v3.15)") – If one of the elements of `sigma` is not a `positive number`.
    

Example

```python
>>> from torchmetrics.functional.image import universal_image_quality_index
>>> preds = torch.rand([16, 1, 16, 16])
>>> target = preds * 0.75
>>> universal_image_quality_index(preds, target)
tensor(0.9216)
```

References

\[1\] Zhou Wang and A. C. Bovik, “A universal image quality index,” in IEEE Signal Processing Letters, vol. 9, no. 3, pp. 81-84, March 2002, doi: 10.1109/97.995823.

\[2\] Zhou Wang, A. C. Bovik, H. R. Sheikh and E. P. Simoncelli, “Image quality assessment: from error visibility to structural similarity,” in IEEE Transactions on Image Processing, vol. 13, no. 4, pp. 600-612, April 2004, doi: 10.1109/TIP.2003.819861.

---

**Navigation**

- Parent: [Image](/docs/torchmetrics/1.9.0/image.md)
