Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.