Skip to content

Instantly share code, notes, and snippets.

@gifguide2code
Created June 10, 2018 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gifguide2code/feafbab1514f57543f120668e35d47f5 to your computer and use it in GitHub Desktop.
Save gifguide2code/feafbab1514f57543f120668e35d47f5 to your computer and use it in GitHub Desktop.
A Python script to filter out pixels with a red value higher than 30.
from PIL import Image
im = Image.open('C:\\Users\\Desktop\\HexTest.png')
pix = im.load()
width = im.size[0]
height = im.size[1]
new_im = Image.new('RGB', (width,height), "white")
new_pix = new_im.load()
for y in range(height):
for x in range(width):
if pix[x,y][0] < 30:
new_pix[x,y] = pix[x,y]
new_im.save('C:\\Users\\Desktop\\HexTest_New.png')
print('Done')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment