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...
How do I set up attributes in Java with "range values? " for example. GameField is...
How do I set up attributes in Java with "range values? " for example. GameField is my class. GameField will have the following attributes: hitPoints – range 0 to 125 strength – range 0 to 20
(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":...
In Python, I have a dictionary where the key is the stem and the value is...
In Python, I have a dictionary where the key is the stem and the value is a list of words with that stem, like this: d= {‘achiev’: [‘achieved’, ‘achieve’] ‘accident’: [‘accidentally’, ‘accidental’] … } #over 1000 items in the dictionary. How can I do for the 25 dictionary entries with the longest lists, print the stem and its list. Thank you!
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)
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 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())
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)?
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT