We can use the convert() function with the 'L' parameter to change an RGB color image into a gray-level image, as shown in the following code:
im_g = im.convert('L') # convert the RGB color image to a grayscale image
We are going to use this image for the next few gray-level transformations.