def rgb_to_gray(img):
    """
    Converts RGB image to greyscale

    Args:
        img (n,m,3 numpy matrix): RGB image

    Returns:
        n,m numpy matrix: Greyscale image
    """
    r, g, b = img[:, :, 0], img[:, :, 1], img[:, :, 2]
    gray = 0.2989 * r + 0.5870 * g + 0.1140 * b
    return gray