Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PIL import Image
- import glob, os
- def color_map(pixel):
- R, G, B = pixel
- brightness = (sum([R, G, B]) / 3) / 255 # 0.0 is dark, 1.0 is bright
- new_pixel = gradient(brightness, (26, 20, 35), (171, 132, 118))
- return new_pixel
- def gradient(factor, start_color, end_color):
- r = start_color[0] + (end_color[0] - start_color[0]) * factor
- g = start_color[1] + (end_color[1] - start_color[1]) * factor
- b = start_color[2] + (end_color[2] - start_color[2]) * factor
- return (int(r), int(g), int(b))
- def load_textures(dir):
- images = []
- for filename in glob.glob(dir):
- im = Image.open(filename).convert('RGB')
- images.append(im)
- return images
- myGradient = ['#1A1423', '#684756', '#AB8476']
- root = 'C://Users//User//PycharmProjects//GradientMap'
- giga_filenames = os.listdir(root + '//input//giga')
- giga_textures = load_textures('input/giga/*.png')
- def main():
- for i in range(0, len(giga_textures)):
- img = giga_textures[i]
- pixels = img.load()
- for x in range(img.size[0]):
- for y in range(img.size[1]):
- this_pixel = img.getpixel((x, y))
- pixels[x, y] = color_map(this_pixel)
- img.save('output/giga/' + giga_filenames[i])
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement