Last active
November 6, 2021 05:41
-
-
Save liuhao2050/5808d73731b50f8abbdcb3c3c5c1e6fa to your computer and use it in GitHub Desktop.
A demo to change a picture's background use python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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