Ask coding questions

← Back to all posts
i can't change the color of my picture
GurleenSINGHKAU (2)

i want to change a picture in grey but even with the formula, I can't do it
here my replit

from PIL import Image
Image=Image.open("pomme")
largeur,hauteur=Image.size
for x in range(largeur):
for y in range(hauteur):
R,V,B=Image.getpixel(x,y)
n-r=R299//1000
n--v=V
587//1000
n--b=B*114//1000
Image.putpixel(x,y),((n-r,n-v,n-b))
Image.save("pomme grise")

Comments
hotnewtop
Geocube101 (628)

You can convert a picture by doing...

from PIL import Image
image = Image(path)
gray = image.convert('L')
gray.save(new_path)

In the case you can't load the PIL module, then...

from os import system
system('pip install Pillow)