convert RGB to grayscale python numpyu code example
Example 1: convert an image to grayscale python using numpy array
1
2
3
4
5
6
7
import numpy as np
from PIL import Image
im = np.array(Image.open('kolala.jpeg').convert('L')) #you can pass multiple arguments in single line
print(type(im))
gr_im= Image.fromarray(im).save('gr_kolala.png')
Example 2: rgb to grayscale python
from PIL import Image
img = Image.open('image.png').convert('LA')
img.save('greyscale.png')