Skip to content
Advertisement

Change RGB of an Image using python

I’m trying to change the color of an image using RGB values in python, for example, if I want to change my image to grayscale I want to be able to manipulate the RGB values of the image. I’ve read that if I want my image in grayscale I would have to do something like Gray = (RedValue + GreenValue + BlueValue) / 3.

Here’s my attempt code:

JavaScript

I made a function called gray where I reloaded the image and change it’s colors, but I don’t want that, I want to apply changes to the image I loaded.

Hope you can help me out.

Advertisement

Answer

Try this:

JavaScript

It loops through all of the pixels and converts each one to grey scale. For some reason, if you press it multiple times it will turn the image into white. I have no idea why.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement