def scale_intrinsics(K, x_scale, y_scale):
    """Scale intrinsic matrix (B33, or 33) given x and y-axes scales.
    Note: This function works for both torch and numpy.

    Parameters
    ----------
    x_scale: float
        x-axis scale factor.
    y_scale: float
        y-axis scale factor.

    Returns
    -------
    torch.FloatTensor (33 or B33)
        Scaled camera intrinsic matrix
    """
    K[..., 0, 0] *= x_scale
    K[..., 1, 1] *= y_scale
    K[..., 0, 2] = (K[..., 0, 2] + 0.5) * x_scale - 0.5
    K[..., 1, 2] = (K[..., 1, 2] + 0.5) * y_scale - 0.5
    return K