# Spatialcorrelationcoefficient

> Compute the SpatialCorrelationCoefficient metric — provided by torchmetrics. Use when the user has predictions and ground-truth and needs to compute SpatialCorrelationCoefficient, or asks how to score with SpatialCorrelationCoefficient.

- Skill: `qhjqhj00/spatialcorrelationcoefficient` (Agent Skill)
- Install (CLI): `npx skillmds add qhjqhj00/spatialcorrelationcoefficient`
- Raw SKILL.md: https://api.skillmd.com/api/skills/qhjqhj00/spatialcorrelationcoefficient/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: qhjqhj00 (https://skillmd.com/u/qhjqhj00)
- Updated: 2026-09-08
- Page: https://skillmd.com/skills/qhjqhj00/spatialcorrelationcoefficient

---


# spatialcorrelationcoefficient

> Metric `SpatialCorrelationCoefficient` from `torchmetrics` (torchmetrics.image.SpatialCorrelationCoefficient)

## When to invoke this skill

The user has predictions + ground truth and asks to evaluate with SpatialCorrelationCoefficient, or
mentions `torchmetrics.image.SpatialCorrelationCoefficient` directly, or wants the standard torchmetrics implementation.

## Reference signature

```python
from torchmetrics.image import SpatialCorrelationCoefficient

# SpatialCorrelationCoefficient(high_pass_filter: Optional[torch.Tensor] = None, window_size: int = 8, **kwargs: Any) -> None
```

## Library docstring

```
Compute Spatial Correlation Coefficient (SCC_).

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

- ``preds`` (:class:`~torch.Tensor`): Predictions from model of shape ``(N,C,H,W)`` or ``(N,H,W)``.
- ``target`` (:class:`~torch.Tensor`): Ground truth values of shape ``(N,C,H,W)`` or ``(N,H,W)``.

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

- ``scc`` (:class:`~torch.Tensor`): Tensor with scc score

Args:
    hp_filter: High-pass filter tensor. default: tensor([[-1,-1,-1],[-1,8,-1],[-1,-1,-1]]).
    window_size: Local window size integer. default: 8.
    kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.

Example:
    >>> from torch import randn
    >>> from torchmetrics.image import SpatialCorrelationCoefficient as SCC
    >>> preds = randn([32, 3, 64, 64])
    >>> target = randn([32, 3, 64, 64])
    >>> scc = SCC()
    >>> scc(preds, target)
    tensor(0.0023)
```

## Quick recipe

```python
import torchmetrics.image as _m
score = _m.SpatialCorrelationCoefficient(y_true, y_pred)
```

## Don'ts

- Don't reimplement when the library version handles edge cases (NaN, ties, empty inputs) better than a hand-rolled formula.
- Always check the library version's argument order — sklearn is `(y_true, y_pred)` while torchmetrics is `(preds, target)`.

