Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. import random
  2. from PIL import Image, ImageDraw #Подключим необходимые библиотеки.
  3.  
  4. def is_black(pixel):
  5. ok = 1
  6. ok &= pixel[0] < 20
  7. ok &= pixel[1] < 20
  8. ok &= pixel[2] < 20
  9. return ok
  10.  
  11. images = ['car.jpg', 'cat.jpg', 'dog.jpg', 'girl.jpg']
  12. image, draw, h, w, pix = [], [], [], [], []
  13. for i in images:
  14. _image = Image.open(i)
  15. image.append(_image)
  16. draw.append(ImageDraw.Draw(_image))
  17. w.append(_image.size[0])
  18. h.append(_image.size[1])
  19. pix.append(_image.load())
  20.  
  21.  
  22. w, h = 4000, 2000
  23. for i in range(1, 4):
  24. for x in range(w):
  25. for y in range(h):
  26. pixel = pix[0][x, y]
  27. second = pix[i][x, y]
  28. new_point = []
  29. is1, is2 = is_black(pixel), is_black(second)
  30. if (is1 and is2):
  31. new_point = (255, 255, 255)
  32. else: new_point = (0, 0, 0)
  33. draw[0].point((x, y), new_point)
  34. #draw.point((i, j), (a, b, c))
  35. image[0].save("ansand.jpg", "JPEG")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement