Compute the PeakSignalNoiseRatioWithBlockedEffect metric — provided by torchmetrics. Use when the user has predictions and ground-truth and needs to compute PeakSignalNoiseRatioWithBlockedEffect, or asks how to score with PeakSignalNoiseRatioWithBlockedEffect.
Installs into .claude/skills of the current project.
Are you the author of Peaksignalnoiseratiowithblockedeffect?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/qhjqhj00-peaksignalnoiseratiowithblockedeffect)
---
name: peaksignalnoiseratiowithblockedeffect
description: Compute the PeakSignalNoiseRatioWithBlockedEffect metric — provided by torchmetrics. Use when the user has predictions and ground-truth and needs to compute PeakSignalNoiseRatioWithBlockedEffect, or asks how to score with PeakSignalNoiseRatioWithBlockedEffect.
metadata:
skill_kind: metric
source_lib: torchmetrics
import_path: torchmetrics.image.PeakSignalNoiseRatioWithBlockedEffect
source: library_introspection
---
# peaksignalnoiseratiowithblockedeffect
> Metric `PeakSignalNoiseRatioWithBlockedEffect` from `torchmetrics` (torchmetrics.image.PeakSignalNoiseRatioWithBlockedEffect)
## When to invoke this skill
The user has predictions + ground truth and asks to evaluate with PeakSignalNoiseRatioWithBlockedEffect, or
mentions `torchmetrics.image.PeakSignalNoiseRatioWithBlockedEffect` directly, or wants the standard torchmetrics implementation.
## Reference signature
```python
from torchmetrics.image import PeakSignalNoiseRatioWithBlockedEffect
# PeakSignalNoiseRatioWithBlockedEffect(data_range: Union[float, tuple[float, float]], block_size: int = 8, **kwargs: Any) -> None
```
## Library docstring
```
Computes `Peak Signal to Noise Ratio With Blocked Effect`_ (PSNRB).
.. math::
\text{PSNRB}(I, J) = 10 * \log_{10} \left(\frac{\max(I)^2}{\text{MSE}(I, J)-\text{B}(I, J)}\right)
Where :math:`\text{MSE}` denotes the `mean-squared-error`_ function. This metric is a modified version of PSNR that
better supports evaluation of images with blocked artifacts, that oftens occur in compressed images.
.. attention::
Metric only supports grayscale images. If you have RGB images, please convert them to grayscale first.
As input to ``forward`` and ``update`` the metric accepts the following input
- ``preds`` (:class:`~torch.Tensor`): Predictions from model of shape ``(N,1,H,W)``
- ``target`` (:class:`~torch.Tensor`): Ground truth values of shape ``(N,1,H,W)``
As output of `forward` and `compute` the metric returns the following output
- ``psnrb`` (:class:`~torch.Tensor`): float scalar tensor with aggregated PSNRB value
Args:
data_range: the range of the data. If a tuple is provided then the range is calculated as the difference and
input is clamped between the values.
block_size: integer indication the block size
kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.
Example:
>>> from torch import rand
>>> metric = PeakSignalNoiseRatioWithBlockedEffect(data_range=1.0)
>>> preds = rand(2, 1, 10, 10)
>>> target = rand(2, 1, 10, 10)
>>> metric(preds, target)
tensor(7.2893)
```
## Quick recipe
```python
import torchmetrics.image as _m
score = _m.PeakSignalNoiseRatioWithBlockedEffect(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)`.