我正在尝试创建一个代码来转换图片中特定像素的RBG值。这是我到目前为止的代码:
所以我已经为像素的新颜色输入新的RGB值,但我很难过如何为像素实际输入这些值。谢谢,任何帮助表示赞赏!
答案 0 :(得分:1)
这就是我想出来的。
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)