Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. from Cimpl import *
  2. import Cimpl
  3.  
  4. file = choose_file()
  5. original_image = load_image(file)
  6.  
  7.  
  8. def three_tone(image: Image, colour_1: str, colour_2: str, colour_3: str) -> Image:
  9. """Function takes an image file and three colours as strings from the given
  10. list:
  11. black
  12. white
  13. red
  14. lime
  15. blue
  16. yellow
  17. cyan
  18. magenta
  19. gray
  20. Function returns an image in three tones (as per the colours given in the
  21. second, third and fourth function parameters) decided by an individual
  22. pixel's brightness.
  23. -Function written by Nathan Gomes, 101143780
  24.  
  25. >>> three_tone(image_1, "blue", "gray", "white")
  26. #Gives the image in only blue, gray and white tones.
  27. >>> three_tone(image_1, "yellow", "cyan", "purple")
  28. #Error because colour passed ("purple") is not in the given list
  29. """
  30.  
  31. black = create_color(0, 0, 0)
  32. white = create_color(255, 255, 255)
  33. red = create_color(255, 0, 0)
  34. lime = create_color(0, 255, 0)
  35. blue = create_color(0, 0, 255)
  36. yellow = create_color(255, 255, 0)
  37. cyan = create_color(0, 255, 255)
  38. magenta = create_color(255, 0, 255)
  39. gray = create_color(128, 128, 128)
  40.  
  41. L = [("black", black), ("white", white), ("red", red), ("lime", lime),
  42. ("blue", blue), ("yellow", yellow), ("cyan", cyan),
  43. ("magenta", magenta), ("gray", gray)]
  44.  
  45. new_image = copy(image)
  46. for pixel in new_image:
  47. x, y, (r, g, b) = pixel
  48. average = (r + g + b) / 3
  49. if (average >= 0) and (average < 85):
  50. for i in range(len(L)):
  51. if colour_1 == L[i][0]:
  52. set_color(new_image, x, y, L[i][1])
  53. elif (average > 84) and (average < 171):
  54. for i in range(len(L)):
  55. if colour_2 == L[i][0]:
  56. set_color(new_image, x, y, L[i][1])
  57. elif (average > 170) and (average < 256):
  58. for i in range(len(L)):
  59. if colour_3 == L[i][0]:
  60. set_color(new_image, x, y, L[i][1])
  61.  
  62. return new_image
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement