Created
April 3, 2012 00:05
-
-
Save glenrobertson/2288152 to your computer and use it in GitHub Desktop.
get PIL white noise image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
def get_white_noise_image(width, height): | |
pil_map = Image.new("RGBA", (width, height), 255) | |
random_grid = map(lambda x: ( | |
int(random.random() * 256), | |
int(random.random() * 256), | |
int(random.random() * 256) | |
), [0] * width * height) | |
pil_map.putdata(random_grid) | |
return pil_map |
Jawwadjlf
commented
Mar 30, 2017
thanks
if you use python3: pil_map.putdata(list(random_grid))
It is much cheaper to do:
from PIL import Image
def get_white_noise_image(w,h):
pil_map = Image.fromarray(np.random.randint(0,255,(w,h,3),dtype=np.dtype('uint8')))
return pil_map
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment