Question

How can I set a specific pixel's RGB value in PIL in Python? For example if...

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)?

Homework Answers

Answer #1
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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Python: Write a RegEx that can check if a string is a specific date format; For...
Python: Write a RegEx that can check if a string is a specific date format; For example dateString = '11-09-2016'
Python: Write a RegEx that can check if a string is in a specific date format;...
Python: Write a RegEx that can check if a string is in a specific date format; For example dateString = '15 November 2009'
How to calculate Pixel position when zoom in or zoom out an image in c# ....
How to calculate Pixel position when zoom in or zoom out an image in c# . I have an application in c# that displayed image when I clicked with mouse at a point on the image it give the pixel value for that point (using e.x and e.y). now i zoom in or out the image. How to get the pixel of the same point in zoomed position on run time. (I don't want to click again at the same...
(Python 3) If I have a list of keys and 3 lists of values, how can...
(Python 3) If I have a list of keys and 3 lists of values, how can I append these values into an existing key, value pair in a dictionary? Say I have: mykeys = ["John", "Sarah", "Lexi, "Cass"] values1 = [3, 5, 2, 6] values2 = [17, 18, 12, 21] values3 = [4, 7, 3, 0] How can I make it so my dictionary contains all three values in each of the keys. i.e.: {"John" : [3, 17, 4], "Sarah":...
Can i please have a template or an example on how i could write up a...
Can i please have a template or an example on how i could write up a portfolio on Developing Effective Teaching and Learning. Can i please have some guidance or template how i can write 'Planning of the project and research task'. Where i have to include the Aim, research question, and rationale.. (how can i write a good rationale)
How can I change my username so that the getuser Python output is different? I am...
How can I change my username so that the getuser Python output is different? I am using a windows pc import datetime import getpass print("\n\nFinished execution at ", datetime.datetime.now()) print(getpass.getuser())
Provide a specific example of a large dataset, and how it can be used. What are...
Provide a specific example of a large dataset, and how it can be used. What are some of the challenges of working with large datasets, and how you think you can overcome these challenges?
how can the "time value of money" concept affect the valuation of liabilities? For example, how...
how can the "time value of money" concept affect the valuation of liabilities? For example, how can this concept be used to determine the price of bond? In contrast, how can it be used to help us plan for a specific goal (e.g., purchase of a car, home, or retirement)?
Provide a specific example of a large dataset, and how it can be used in your...
Provide a specific example of a large dataset, and how it can be used in your current or future career. What are some of the challenges of working with large datasets, and how you think you can overcome these challenges?
In Python (using pandas and numpy) I have a CSV list (example.csv) and I am looking...
In Python (using pandas and numpy) I have a CSV list (example.csv) and I am looking to find the average age of the males in my data set. How would I make a function ('avg_age_males') that finds and outputs the average age for just the males in the data set? (In the .csv males is represented by 'M' and females is represented by 'F')