from PIL import Image
import matplotlib.pyplot as plt
rgb2gray
A library to convert RGB images to grayscale.
Install
pip install rgb2gray
How to use
An example with rgb2gray
package.
= rgb2gray(Image.new('RGB', (10, 10), color = (255,255,0)))
result result
array([[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)
='gray')
plt.imshow(result, cmap; 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()