---
title: Quality with No Reference
description: Compute Quality with No Reference (QualityWithNoReference) also now as QNR.
canonical: 'https://lightning.ai/docs/torchmetrics/stable/image/quality_with_no_reference'
---
# Quality with No Reference {#quality-with-no-reference}

## Module Interface {#module-interface}

### `class torchmetrics.image.QualityWithNoReference(alpha=1, beta=1, norm_order=1, window_size=7, reduction='elementwise_mean', **kwargs)` {#torchmetrics.image.QualityWithNoReference}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/image/qnr.py#L36-L227)

Compute Quality with No Reference ([QualityWithNoReference](https://www.semanticscholar.org/paper/Multispectral-and-panchromatic-data-fusion-without-Alparone-Aiazzi/b6db12e3785326577cb95fd743fecbf5bc66c7c9)) also now as QNR.

The metric is used to compare the joint spectral and spatial distortion between two images.

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)")): High resolution multispectral image of shape `(N,C,H,W)`.
    
*   `target` (`Dict`): A dictionary containing the following keys:
    
    *   `ms` ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")): Low resolution multispectral image of shape `(N,C,H',W')`.
        
    *   `pan` ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")): High resolution panchromatic image of shape `(N,C,H,W)`.
        
    *   `pan_lr` ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")): (optional) Low resolution panchromatic image of shape `(N,C,H',W')`.
        

where H and W must be multiple of H’ and W’.

When `pan_lr` is `None`, a uniform filter will be applied on `pan` to produce a degraded image. The degraded image is then resized to match the size of `ms` and served as `pan_lr` in the calculation.

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

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

Parameters:

*   **alpha** ([`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)")) – Relevance of spectral distortion.
    
*   **beta** ([`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)")) – Relevance of spatial distortion.
    
*   **norm\_order** ([`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")) – Order of the norm applied on the difference.
    
*   **window\_size** ([`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")) – Window size of the filter applied to degrade the high resolution panchromatic image.
    
*   **reduction** ([`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'`: 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.
    

Example

```python
>>> from torch import rand
>>> from torchmetrics.image import QualityWithNoReference
>>> preds = rand([16, 3, 32, 32])
>>> target = {
...     'ms': rand([16, 3, 16, 16]),
...     'pan': rand([16, 3, 32, 32]),
... }
>>> qnr = QualityWithNoReference()
>>> qnr(preds, target)
tensor(0.9694)
```

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

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/image/qnr.py#L177-L227)

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
>>> from torch import rand
>>> from torchmetrics.image import QualityWithNoReference
>>> preds = rand([16, 3, 32, 32])
>>> target = {
...     'ms': rand([16, 3, 16, 16]),
...     'pan': rand([16, 3, 32, 32]),
... }
>>> metric = QualityWithNoReference()
>>> metric.update(preds, target)
>>> fig_, ax_ = metric.plot()
```

[![../../\_images/quality\_with\_no\_reference-1.png](/docs/torchmetrics/1.9.0/static/_images/quality_with_no_reference-1.png)](/docs/torchmetrics/1.9.0/static/_images/quality_with_no_reference-1.png)

```python
>>> # Example plotting multiple values
>>> from torch import rand
>>> from torchmetrics.image import QualityWithNoReference
>>> preds = rand([16, 3, 32, 32])
>>> target = {
...     'ms': rand([16, 3, 16, 16]),
...     'pan': rand([16, 3, 32, 32]),
... }
>>> metric = QualityWithNoReference()
>>> values = [ ]
>>> for _ in range(10):
...     values.append(metric(preds, target))
>>> fig_, ax_ = metric.plot(values)
```

[![../../\_images/quality\_with\_no\_reference-2.png](/docs/torchmetrics/1.9.0/static/_images/quality_with_no_reference-2.png)](/docs/torchmetrics/1.9.0/static/_images/quality_with_no_reference-2.png)

## Functional Interface {#functional-interface}

### `torchmetrics.functional.image.quality_with_no_reference(preds, ms, pan, pan_lr=None, alpha=1, beta=1, norm_order=1, window_size=7, reduction='elementwise_mean')` {#torchmetrics.functional.image.quality_with_no_reference}

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

Calculate [Quality with No Reference](#quality-with-no-reference) ([QualityWithNoReference](https://www.semanticscholar.org/paper/Multispectral-and-panchromatic-data-fusion-without-Alparone-Aiazzi/b6db12e3785326577cb95fd743fecbf5bc66c7c9)) also known as QNR.

Metric is used to compare the joint spectral and spatial distortion between two images.

Parameters:

*   **preds** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – High resolution multispectral image.
    
*   **ms** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – Low resolution multispectral image.
    
*   **pan** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – High resolution panchromatic image.
    
*   **pan\_lr** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")\]) – Low resolution panchromatic image.
    
*   **alpha** ([`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)")) – Relevance of spectral distortion.
    
*   **beta** ([`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)")) – Relevance of spatial distortion.
    
*   **norm\_order** ([`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")) – Order of the norm applied on the difference.
    
*   **window\_size** ([`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")) – Window size of the filter applied to degrade the high resolution panchromatic image.
    
*   **reduction** ([`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'`: 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 QualityWithNoReference score

Raises:

[**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError "(in Python v3.15)") – If `alpha` or `beta` is not a non-negative real number.

Example

```python
>>> from torch import rand
>>> from torchmetrics.functional.image import quality_with_no_reference
>>> preds = rand([16, 3, 32, 32])
>>> ms = rand([16, 3, 16, 16])
>>> pan = rand([16, 3, 32, 32])
>>> quality_with_no_reference(preds, ms, pan)
tensor(0.9694)
```

---

**Navigation**

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