Oct-10-2018, 08:57 AM
Hi,
I am trying to use pillow for an online python photo manipulation course, I am only starting at the basics one of my tasks is to write a program which keeps only the blue channel from an image. Their hint is to loop through the pixels in the image and set the red and green values of each pixel to 0. The code I am trying is:
Can anybody help with this?
Thanks.
I am trying to use pillow for an online python photo manipulation course, I am only starting at the basics one of my tasks is to write a program which keeps only the blue channel from an image. Their hint is to loop through the pixels in the image and set the red and green values of each pixel to 0. The code I am trying is:
from PIL import Image file = input("File name: ") img = Image.open(file) red, green, blue = img.split() for y in range (red.height): for x in range (red.width): img.putpixel((x, y), 0) for y in range (green.height): for x in range (green.width): img.putpixel((x, y), 0) new_image = Image.merge ('RGB', (red, green, blue)) img.save("output.png")However, after I do this, I only get an image that is totally black.
Can anybody help with this?
Thanks.