def ssim(test, ref, mask=None):
    """Structural Similarity (SSIM)

    Calculate the SSIM between a test image and a reference image.

    Parameters
    ----------
    ref : np.ndarray
        the reference image
    test : np.ndarray
        the tested image
    mask : np.ndarray, optional
        the mask for the ROI

    Notes
    -----
    Compute the metric only on magnetude.

    Returns
    -------
    ssim: float, the snr

    """

    if not import_skimage:  # pragma: no cover
        raise ImportError('Scikit-Image package not found')

    test, ref, mask = _preprocess_input(test, ref, mask)
    assim, ssim = compare_ssim(test, ref, full=True)

    if mask is None:
        return assim

    else:
        return (mask * ssim).sum() / mask.sum()