Image模块。这是一个例子:
from PIL import Imagepicture = 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 Imagepicture = Image.open("/path/to/my/picture.jpg")# Get the size of the imagewidth, height = picture.size()# Process every pixelfor 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)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)