Python Forum
random change of color pixel with PIL
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
random change of color pixel with PIL
#1
Hey !
I wrote this code to randomly change the colors pixels of an image.
The first time, it's good, pixels are randomly changed but after this, it'ls always the same image and pixels...
Can you tell me why ?

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()
Reply


Messages In This Thread
random change of color pixel with PIL - by louloudevinci - May-31-2018, 01:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Voxel to pixel graphics voicemail 3 634 Nov-19-2023, 09:45 AM
Last Post: paul18fr
  Turtle Star Fill Color Yellow-White Interchanging Color Effect codelab 9 1,149 Oct-25-2023, 09:09 AM
Last Post: codelab
  Pixel color and action Sartre 4 2,193 Apr-13-2023, 03:26 AM
Last Post: Sartre
  Dynamic pixel display jerryf 2 765 Mar-17-2023, 07:26 PM
Last Post: jerryf
  simplekml change shape&color issac_n 2 2,899 Aug-20-2022, 07:15 PM
Last Post: Joseph_Paintsil
  Plotting Pixel Intensity Doev 0 1,767 Oct-21-2020, 10:56 PM
Last Post: Doev
  Change the color automatically Dragonos 5 2,959 Jul-28-2020, 01:17 PM
Last Post: Dragonos
  Use of input function to change screen background color in Turtles Oldman45 3 4,992 Jul-10-2020, 09:54 AM
Last Post: Oldman45
  What is the best way to search for a pixel in a screenshot? TheZadok42 1 2,674 May-15-2020, 12:37 PM
Last Post: scidam
  Fast get pixel and oparate. storzo 7 7,246 Aug-26-2019, 07:36 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020