jeudi 31 mai 2018

Why my random change of pixel color doesn't work ? (with PIL)

I wrote this code to change randomly the pixels colors of my image. The random change work one time, but it's all... Afet the first time, it's the same image over and over...

Can you give me a clew ?

from PIL import Image
from random import randint

picture_1 = Image.open("panda.jpg")

largeur, longueur = picture_1.size

print(largeur,"*",longueur)

picture_2 = Image.new("RGB", (largeur, longueur))

for x in range(largeur) :
   for y in range(longueur) :
       (r, g, b) = picture_1.getpixel((x,y))
       r = randint(0,25) ; v = randint(0,255) ; b = randint(0,255)
       picture_2.putpixel((x,y), (r, g, b))


picture_2.save("pandatest6.jpg")
picture_2.show()




Aucun commentaire:

Enregistrer un commentaire