Guest User

Untitled

a guest
Nov 16th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. def picture_reset_pixels(filename, from_color, to_color, target_color):
  2. img = Image.open(filename)
  3. pixels = list(img.getdata())
  4. red_list=[]
  5. for i in pixels:
  6. R= i[0]
  7. G=i[1]
  8. B=i[2]
  9.  
  10. if R >= from_color[0] and R<= to_color[0] and G >=from_color[1]
  11. and G<= to_color[1] and B >= from_color[2] and B<=
  12. to_color[2]:
  13. red_list.append(target_color)
  14. else:
  15. red_list.append((round(R),round(G),round(B)))
  16.  
  17. red_image = Image.new(img.mode,img.size)
  18. red_image.putdata(red_list)
  19. return red_image
Add Comment
Please, Sign In to add comment