from PIL import Image
# open image
image = Image.open('pic.jpeg')
# show the image (optional)
image.show()
# load the image into memory
image_data = image.load()
# obtain sizes
height,width = image.size
# loop over and change blue value to 0
for loop1 in range(height):
for loop2 in range(width):
r,g,b = image_data[loop1,loop2]
image_data[loop1,loop2] = r,g,0
image.save('changed.jpeg')
The corresponding function would be
def remove_blue(image):
image = Image.open('pic.jpeg')
# show the image (optional)
image.show()
# load the image into memory
image_data = image.load()
# obtain sizes
height,width = image.size
# loop over and change blue value to 0
for loop1 in range(height):
for loop2 in range(width):
r,g,b = image_data[loop1,loop2]
image_data[loop1,loop2] = r,g,0
# return image
image.save('changed.jpeg')
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…