def rgb2gray(im):
    """Transforming image from RGB to grayscale.

    Parameters
    ----------
    im : np.array
        matrix of image.

    Returns
    -------
    np.array
        image in gray.

    """
    r, g, b = im[:,:,0], im[:,:,1], im[:,:,2]
    gray = 0.2989 * r + 0.5870 * g + 0.1140 * b
    return gray