bingtuag 发表于 2017-4-26 09:15:58

Python+PIL记录

  PIL(http://www.pythonware.com/products/pil/
)中包含很多图形处理库,主要是Image,Image库中包含三个类(Image、ImagePointHandler、ImageTransformHandler)及若干方法。
  Image模块仅用一个类来表示PIL中的图像,并提供了许多工厂函数,不同类型的图像可以使用统一的接口进行处理。
  http://www.pythonware.com/library/pil/handbook/image.htm



主要函数(可以顾名思义,这里主要有个提纲,方便记忆)有:


写道

    Image.new(mode, size) => image


Image.new(mode, size, color) => image


Image.open(infile) => image


Image.open(infile, mode) => image


Image.blend(image1, image2, alpha) => image


im.convert(mode) => image


im.convert(mode, matrix) => image


im.copy() => image


im.crop(box) => image


im.paste(image, box)


im.paste(colour, box)


im.paste(image, box, mask)


im.paste(colour, box, mask)


im.resize(size) => image


im.resize(size, filter) => image


im.save(outfile, options…)


im.save(outfile, format, options…)


im.seek(frame)   可用于gif


im.split() => sequence    RGB通道分离


im.transpose(method) => image

   图片截取:

file =open("/home/yunpeng/Desktop/solr/test.png",'rb')
im = Image.open(file)
x = 300
y = 500
width = 300
height = 200
box = (x, y, x+width, y+height)
area = im.crop(box)
area.save('/home/yunpeng/Desktop/solr/test2.png', im.format or "JPEG")
   今天实验了一把,打开两个差异很小的图片,将其中一个反色处理,然后在将两个图像混合,就能比较清晰的看到差异的地方。

import Image, ImageChops
im1 = Image.open('c:/1.bmp')
im2 = Image.open('c:/2.bmp')
im3 = ImageChops.invert(im2)
Image.blend(im1,im3,0.5).show()
   原始图片如下:

  1.bmp
http://hi.csdn.net/attachment/201109/10/0_13156695543GE3.gif
  2.bmp
http://hi.csdn.net/attachment/201109/10/0_13156695283UHm.gif
  混合后结果:
http://hi.csdn.net/attachment/201109/10/0_131566970571Z7.gif
页: [1]
查看完整版本: Python+PIL记录