import matplotlib.pyplot as plt
from io import BytesIO
import requests
API details
A simple API for converting an RGB to a grayscale image.
rgb2gray
rgb2gray (img)
Convert RGB image to grayscale.
Here is an example of conversion…
= Image.new('RGB', (10, 10), color = (255,0,0))
red rgb2gray(red)
array([[76, 76, 76, 76, 76, 76, 76, 76, 76, 76],
[76, 76, 76, 76, 76, 76, 76, 76, 76, 76],
[76, 76, 76, 76, 76, 76, 76, 76, 76, 76],
[76, 76, 76, 76, 76, 76, 76, 76, 76, 76],
[76, 76, 76, 76, 76, 76, 76, 76, 76, 76],
[76, 76, 76, 76, 76, 76, 76, 76, 76, 76],
[76, 76, 76, 76, 76, 76, 76, 76, 76, 76],
[76, 76, 76, 76, 76, 76, 76, 76, 76, 76],
[76, 76, 76, 76, 76, 76, 76, 76, 76, 76],
[76, 76, 76, 76, 76, 76, 76, 76, 76, 76]], dtype=uint8)
= plt.subplots(nrows=1, ncols=2, figsize=(10,10))
fig, axes 0].imshow(red)
axes[1].imshow(rgb2gray(red), cmap='gray')
axes[; plt.show()
= Image.open('images/ds.jpg')
img = plt.subplots(nrows=1, ncols=2, figsize=(15,10))
fig, axes
0].imshow(img)
axes[1].imshow(rgb2gray(img), cmap='gray')
axes[; plt.show()