bensimmo

Representing Data with Images and Sound 2.10 clarendon

Jan 21st, 2021 (edited)
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.12 KB | None | 0 0
  1. from PIL import Image    #Import the Image module from the PIL library
  2.  
  3. def clarendon2(values):
  4.     new_values = []
  5.    
  6.     if max(values) < 128: #darks darker
  7.         modify = 0.9
  8.         for colour in range(3):
  9.             new_values.append(int( max(0, values[colour] * modify)))
  10.     else: #lights lighter
  11.         modify = 1.1
  12.         for colour in range(3):
  13.             new_values.append(int( min(255, values[colour] * modify)))
  14.            
  15.     new_values[2] = int(min(255, new_values[2]*1.1)) #blue tint
  16.    
  17.     return tuple(new_values)
  18.                        
  19.  
  20.  
  21. image = Image.open('image.png')    #Create a path to the image file
  22. rgb_image = image.convert('RGB')    #Convert the image to RGB
  23. width, height = image.size     #Assign the image's width and height to variables
  24. new_image2 = Image.new('RGB', (width,height))     #Create a grid for the output image
  25.  
  26. #Set up loops to modify each pixel within the image
  27. for row in range(height):
  28.     for col in range(width):
  29.         rgb  = rgb_image.getpixel((col, row))
  30.         new_image2.putpixel((col, row), clarendon2(rgb))
  31.  
  32. image.show()
  33. new_image2.show()
Add Comment
Please, Sign In to add comment