Reputation: 275
For each pixel in pic:
r= random()
if r < 0.25:
set the red level to randrange(0,256),
set the green level to randrange(0,256)
set the blue level to randrange(0,256)
The rest of the unseen code is correct, I just can't figure out how to phrase this function well enough for it to work.
Upvotes: 1
Views: 2421
Reputation: 277
Are you using PIL?
If so one option is to do something like this
your_image = Image.new("RGB", (512, 512), "white")
for x in xrange(your_image.size[0]):
for y in xrange(your_image.size[1]):
your_image.putpixel((x,y),(random.randint(256), random.randint(256), random.randint(256))
Oh... I see you got it. Well I'll post this anyways.
Upvotes: 0
Reputation: 4623
I don't know anything about the rest of your code, but it would be something like this:
import random
for pixel in pic.get_pixels(): # Replace with appropiate way of getting the pixels
if random.random() < 0.25:
pixel.red = random.randint(256)
pixel.green = random.randint(256)
pixel.blue = random.randint(256)
Again, I don't know how you get a list of the pixels, or how you set the RGB values for each one, but the result would be something like this.
Upvotes: 1