Advertisement
Guest User

BW filter

a guest
Apr 6th, 2020
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1. from PIL import Image
  2.  
  3. image = Image.open('image.png')
  4.  
  5. rgb_im = image.convert('RGB')
  6.  
  7. width, height = image.size
  8.  
  9. output_image = Image.new('RGB', (width, height))
  10.  
  11. for row in range(height):
  12.     for col in range(width):
  13.         r, g, b = rgb_im.getpixel((col, row))
  14.         if (r < 128):
  15.             p = 0
  16.         else:
  17.             p = 255
  18.         output_image.putpixel((col, row), (p,p,p))
  19.        
  20.  
  21. output_image.save("bw.png")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement