def nrmse(test, ref, mask=None):
    """Return NRMSE

    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 magnitude.

    Returns
    -------
    nrmse: float, the nrmse

    """

    test, ref, mask = _preprocess_input(test, ref, mask)

    if mask is not None:
        test = mask * test
        ref = mask * ref

    num = np.sqrt(mse(test, ref))
    deno = np.sqrt(np.mean((np.square(test))))

    return num / deno