from PIL import Image
import matplotlib.pyplot as pltrgb2gray
    A library to convert RGB images to grayscale.
  
Install
pip install rgb2gray
How to use
An example with rgb2gray package.
result = rgb2gray(Image.new('RGB', (10, 10), color = (255,255,0)))
resultarray([[226, 226, 226, 226, 226, 226, 226, 226, 226, 226],
       [226, 226, 226, 226, 226, 226, 226, 226, 226, 226],
       [226, 226, 226, 226, 226, 226, 226, 226, 226, 226],
       [226, 226, 226, 226, 226, 226, 226, 226, 226, 226],
       [226, 226, 226, 226, 226, 226, 226, 226, 226, 226],
       [226, 226, 226, 226, 226, 226, 226, 226, 226, 226],
       [226, 226, 226, 226, 226, 226, 226, 226, 226, 226],
       [226, 226, 226, 226, 226, 226, 226, 226, 226, 226],
       [226, 226, 226, 226, 226, 226, 226, 226, 226, 226],
       [226, 226, 226, 226, 226, 226, 226, 226, 226, 226]], dtype=uint8)plt.imshow(result, cmap='gray')
plt.show();
img = Image.open('images/ds.jpg')
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(15,10))
axes[0].imshow(img)
axes[1].imshow(rgb2gray(img), cmap='gray')
plt.show();