How can I set a specific pixel's RGB value in PIL in Python?
For example if I have an image X, how can I set the pixel at coordinate (8,23) to an RGB value of (220, 20, 60)?
from PIL import Image
im = Image.open("X.jpg") #Opens the Given image using the Image class of the PIL Library into the object im
im.putpixel((8, 23), (220, 20, 60)) #The pixel of 8,23 is replaced with the specified RGB value.
im = im.save("X.jpg") #The image is saved to rewrite the existing image.
Code Explained with Comments, please do comment if anything else is needed
Get Answers For Free
Most questions answered within 1 hours.