Oct-13-2018, 02:46 AM
(This post was last modified: Oct-13-2018, 02:47 AM by I_Am_Groot.)
Hi,
For one of the tasks in my assignment, I have to highlighting a single colour in a black and white image. It says: In your program, any pixels which are not red should be made black and white by taking the average of the red, green, and blue channels.
I have tried making the blue and green channels grayscale and keeping the red channel the same but it still has a red tinge on the whole picture when I just want it on a certain item.
The starting image is:
![[Image: HuuU86H]](https://imgur.com/HuuU86H)
And the end product should be:

The code I tried was:
![[Image: KSvHC96]](https://imgur.com/KSvHC96)
If you know anything it will be great help.
Thanks.
For one of the tasks in my assignment, I have to highlighting a single colour in a black and white image. It says: In your program, any pixels which are not red should be made black and white by taking the average of the red, green, and blue channels.
I have tried making the blue and green channels grayscale and keeping the red channel the same but it still has a red tinge on the whole picture when I just want it on a certain item.
The starting image is:
And the end product should be:
The code I tried was:
from PIL import Image file = input("File name: ") img = Image.open(file) red,green,blue = img.split() for y in range(img.height): for x in range(img.width): r = red.getpixel((x,y)) g = green.getpixel((x,y)) b = blue.getpixel((x,y)) total = (r+g+b) avg = int((total/3)) green.putpixel((x,y),avg) blue.putpixel((x,y),avg) new_image = Image.merge('RGB', (red, green, blue)) new_image.save("output.png")The end product of that was:
If you know anything it will be great help.
Thanks.