Python+PIL记录

3 篇文章 0 订阅

 

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

 

2.bmp

 

混合后结果:

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值