I am trying to convert a RGB picture to grayscale. I do not want to use image.convert('L'). This just shows the original image without changing anything. I have tried putting different numbers in the 'red,green,blue=0,0,0' line which does change the color of the image but it is not what I want.
import PIL
from PIL import Image
def grayscale(picture):
res=PIL.Image.new(picture.mode, picture.size)
width, height = picture.size
for i in range(0, width):
for j in range(0, height):
red, green, blue = 0,0,0
pixel=picture.getpixel((i,j))
red=red+pixel[0]
green=green+pixel[1]
blue=blue+pixel[2]
avg=(pixel[0]+pixel[1]+pixel[2])/3
res.putpixel((i,j),(red,green,blue))
res.show()
grayscale(Image.show('flower.jpg'))