---
title: Spectral Distortion Index
description: >-
  Compute Spectral Distortion Index (SpectralDistortionIndex) also now as
  D_lambda.
canonical: 'https://lightning.ai/docs/torchmetrics/stable/image/spectral_distortion_index'
---
# Spectral Distortion Index {#spectral-distortion-index}

## Module Interface {#module-interface}

### `class torchmetrics.image.SpectralDistortionIndex(p=1, reduction='elementwise_mean', **kwargs)` {#torchmetrics.image.SpectralDistortionIndex}

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

Compute Spectral Distortion Index ([SpectralDistortionIndex](https://www.semanticscholar.org/paper/Multispectral-and-panchromatic-data-fusion-without-Alparone-Aiazzi/b6db12e3785326577cb95fd743fecbf5bc66c7c9)) also now as D\_lambda.

The metric is used to compare the spectral 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)")): Low resolution multispectral image of shape `(N,C,H,W)`
    
*   ```target``(:class:`~torch.Tensor`): High resolution fused image of shape ``(N,C,H,W)```
    

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

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

Parameters:

*   **p** ([`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")) – Large spectral differences
    
*   **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 SpectralDistortionIndex
>>> preds = rand([16, 3, 16, 16])
>>> target = rand([16, 3, 16, 16])
>>> sdi = SpectralDistortionIndex()
>>> sdi(preds, target)
tensor(0.0234)
```

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

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/image/d_lambda.py#L108-L152)

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 SpectralDistortionIndex
>>> preds = rand([16, 3, 16, 16])
>>> target = rand([16, 3, 16, 16])
>>> metric = SpectralDistortionIndex()
>>> metric.update(preds, target)
>>> fig_, ax_ = metric.plot()
```

[![../../\_images/spectral\_distortion\_index-1.png](/docs/torchmetrics/1.9.0/static/_images/spectral_distortion_index-1.png)](/docs/torchmetrics/1.9.0/static/_images/spectral_distortion_index-1.png)

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

[![../../\_images/spectral\_distortion\_index-2.png](/docs/torchmetrics/1.9.0/static/_images/spectral_distortion_index-2.png)](/docs/torchmetrics/1.9.0/static/_images/spectral_distortion_index-2.png)

## Functional Interface {#functional-interface}

### `torchmetrics.functional.image.spectral_distortion_index(preds, target, p=1, reduction='elementwise_mean')` {#torchmetrics.functional.image.spectral_distortion_index}

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

Calculate [Spectral Distortion Index](https://www.semanticscholar.org/paper/Multispectral-and-panchromatic-data-fusion-without-Alparone-Aiazzi/b6db12e3785326577cb95fd743fecbf5bc66c7c9) ([SpectralDistortionIndex](https://www.semanticscholar.org/paper/Multispectral-and-panchromatic-data-fusion-without-Alparone-Aiazzi/b6db12e3785326577cb95fd743fecbf5bc66c7c9)) also known as D\_lambda.

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

Parameters:

*   **preds** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – Low resolution multispectral image
    
*   **target** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – High resolution fused image
    
*   **p** ([`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")) – Large spectral differences
    
*   **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 SpectralDistortionIndex 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 `p` is not a positive integer.
    

Example

```python
>>> from torch import rand
>>> from torchmetrics.functional.image import spectral_distortion_index
>>> preds = rand([16, 3, 16, 16])
>>> target = rand([16, 3, 16, 16])
>>> spectral_distortion_index(preds, target)
tensor(0.0234)
```

---

**Navigation**

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