Reputation: 19
I am trying to create a code for converting the RBG values of specific pixels in a picture. Here is the code I have thus far:
So I have gotten as far as inputting new RGB values for the new color of the pixel, but I am stumped as how to actually input those for the pixel. Thanks, any help is appreciated!
Upvotes: 1
Views: 806
Reputation: 460
This is what i came up with.
from PIL import Image, ImageFilter
print("enter image file:")
myimage = input()
try:
original = Image.open(myimage)
im = original.load()
except:
print('Invalid file')
# print(myimage)
# print("The size of the Image is: ")
print(original.format, original.size, original.mode)
# pixel_values = list(original.getdata())
'''
for y in range(0, 512):
row = ""
for x in range(0, 512):
row = ""
'''
print("Enter coordinates of desired pixel in x,y form")
coordinates = [int(x) for x in input().split(',')]
x, y = coordinates
R, G, B = im[x, y]
print("R,G,B values corresponding with this pixel are:")
print(R, G, B)
print("enter new R,G,B values")
new_RGB = [int(x) for x in input().split(',')]
r, g, b = new_RGB
im[x, y] = (r, g, b)
original.save(myimage)
Upvotes: 1