Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. import os
  2. import numpy as np
  3. from PIL import Image
  4.  
  5. def lista_immagini():
  6. filelist=os.listdir(r"C:UsersfdivitoDesktopimage")
  7. for fichier in filelist[:]: # filelist[:] makes a copy of filelist.
  8. if not(fichier.endswith(".png")):
  9. filelist.remove(fichier)
  10. print(filelist)
  11. return filelist
  12. brand = {'Ferrari': (0, 47, 128), 'Lamborghini': (196, 18, 48)}
  13.  
  14. for key, value in brand.iteritems():
  15. brand_model = key
  16. color_model_r = value[0]
  17. color_model_g = value[1]
  18. color_model_b = value[2]
  19.  
  20. for i in lista_immagini():
  21. im = Image.open(r'path'+ i)
  22. data = np.array(im)
  23.  
  24. r1, g1, b1 = 54, 115, 51 # Original value
  25. r2, g2, b2 = color_model_r, color_model_g, color_model_b # Value that we want to replace it with
  26.  
  27. red, green, blue = data[:,:,0], data[:,:,1], data[:,:,2]
  28. mask = (red == r1) & (green == g1) & (blue == b1)
  29. data[:,:,:3][mask] = [r2, g2, b2]
  30.  
  31. im = Image.fromarray(data)
  32. im.save(r"path" + brand_model + "_" + i)
  33. print("Done " + str(i))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement