1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > python改变像素点颜色_更改像素颜色Python

python改变像素点颜色_更改像素颜色Python

时间:2020-02-10 16:50:21

相关推荐

python改变像素点颜色_更改像素颜色Python

小编典典

我假设您正在尝试使用该Image模块。这是一个例子:

from PIL import Image

picture = Image.open("/path/to/my/picture.jpg")

r,g,b = picture.getpixel( (0,0) )

print("Red: {0}, Green: {1}, Blue: {2}".format(r,g,b))

在此图像上运行此命令,得到输出:

>>> from PIL import Image

>>> picture = Image.open("/home/gizmo/Downloads/image_launch_a5.jpg")

>>> r,g,b = picture.getpixel( (0,0) )

>>> print("Red: {0}, Green: {1}, Blue: {2}".format(r,g,b))

Red: 138, Green: 161, Blue: 175

编辑:做你想要的我会尝试这样的事情

from PIL import Image

picture = Image.open("/path/to/my/picture.jpg")

# Get the size of the image

width, height = picture.size()

# Process every pixel

for x in width:

for y in height:

current_color = picture.getpixel( (x,y) )

####################################################################

# Do your logic here and create a new (R,G,B) tuple called new_color

####################################################################

picture.putpixel( (x,y), new_color)

-12-20

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。