I am having some trouble with converting the pixels in a colored image to gray using Python. Below is the current code I have for reference:
import numpy as np
from PIL import Image
from matplotlib import pyplot
#load the image
color_image = Image.open('...\\Baby_ginger_monkey.jpg')
#Convert image to numpay array
color_image_data = np.asarray(color_image)
print(type(color_image_data))
#summarize image shape
print(color_image_data.shape)
#display the image
pyplot.imshow(color_image)
pyplot.show()
#convert the image into a gray-level image
gray_image_data = color_image_data.mean(axis=2)
The part I'm having trouble with is that I'm not sure how to take the values in the gray_image_data variable and apply it to the pixels of the image. Any form of help would be greatly appreciated.