Skip to content

Instantly share code, notes, and snippets.

@liuhao2050
Last active November 6, 2021 05:41
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liuhao2050/5808d73731b50f8abbdcb3c3c5c1e6fa to your computer and use it in GitHub Desktop.
Save liuhao2050/5808d73731b50f8abbdcb3c3c5c1e6fa to your computer and use it in GitHub Desktop.
A demo to change a picture's background use python
from PIL import Image
if __name__ == "__main__":
im = Image.open("mr.zhang.jpg")
x, y = im.size
for i in range(x):
for j in range(y):
r, g, b = im.getpixel((i,j))
if (20< r < 180) and (80< g < 250) and (180< b< 265):
r, g, b = 255, 255, 255
im.putpixel((i, j), (r, g, b))
im.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment