mrpro.operators.functionals.SSIM
- class mrpro.operators.functionals.SSIM[source]
Bases:
Functional
(masked) SSIM functional.
- __init__(target: Tensor, weight: Tensor | None = None, *, data_range: Tensor | None = None, window_size: int = 7, k1: float = 0.01, k2: float = 0.03, reduction: Literal['full', 'volume', 'none'] = 'full') None [source]
Initialize Volume SSIM.
The Structural Similarity Index Measure [SSIM] is used to measure the similarity between two images. It considers luminance, contrast and structure differences between the images. SSIM values range from -1 to 1, where 1 indicates perfect structural similarity. Two random images have an SSIM of 0.
Calculates the SSIM using a rectangular sliding window. If a boolean mask is used as weight, only the windows that are fully inside the mask are considered. This can be used to ignore the background of the volumes. Calculates the SSIM for a volume, i.e, 3D patches of the last three dimensions of the input are used. To apply it to 2D data, add a singleton dimension. For complex inputs, the SSIM is calculated separately for the real and imaginary parts and the results are averaged.
For stability, it is advised to provide the data range. Otherwise it is estimates per volume from the target.
References
[SSIM]Wang, Z., Bovik, A. C., Sheikh, H. R., & Simoncelli, E. P. (2004). Image quality assessment: from error visibility to structural similarity. IEEE TMI, 13(4), 600-612. https://doi.org/10.1109/TIP.2003.819861
- Parameters:
target (
Tensor
) – Target volume. At least three dimensional.weight (
Tensor
|None
, default:None
) – Either a boolean mask. Only windows with all valuesTrue
will be considered. Or a weight tensor of the same shape as the target. Each window will be weighted by the average value of the weight in the window. Only windows with all weight values > 0 will be considered. OrNone
, meaning all windows are used.data_range (
Tensor
|None
, default:None
) – Value range if the data. If None, the max-to-min per volume of the target will be used.window_size (
int
, default:7
) – Size of the windows used in SSIM. Usually7
or11
. If any of the last 3 dimensions of the target is of size 1, the window size in this dimension will also be set to 1.k1 (
float
, default:0.01
) – Constant. Usually0.01
and rarely changed.k2 (
float
, default:0.03
) – Constant. Usually0.03
and rarely changed.reduction (
Literal
['full'
,'volume'
,'none'
], default:'full'
) – Iffull
, return the weighted mean SSIM over all windows, i.e. a scalar value. Ifvolume
, return one value for each volume, i.e, antarget.ndim - 3
dimensional tensor. Ifnone
, return the unpadded SSIM map.
- __call__(*args: Unpack[Tin]) Tout [source]
Apply the forward operator.
For more information, see
forward
.
- __add__(other: Operator[Unpack[Tin], Tout]) Operator[Unpack[Tin], Tout] [source]
- __add__(other: Tensor) Operator[Unpack[Tin], tuple[Unpack[Tin]]]
Operator addition.
Returns
lambda x: self(x) + other(x)
if other is a operator,lambda x: self(x) + other*x
if other is a tensor
- __matmul__(other: Operator[Unpack[Tin2], tuple[Unpack[Tin]]]) Operator[Unpack[Tin2], Tout] [source]
Operator composition.
Returns
lambda x: self(other(x))
- __mul__(other: Tensor | complex) Operator[Unpack[Tin], Tout] [source]
Operator multiplication with tensor.
Returns
lambda x: self(x*other)
- __radd__(other: Tensor) Operator[Unpack[Tin], tuple[Unpack[Tin]]] [source]
Operator right addition.
Returns
lambda x: other*x + self(x)
- __rmul__(scalar: Tensor | complex) Functional [source]
Multiply functional with scalar.