使用Python+PIL查看两张相似图形的差异
2011-09-10 23:49
543 查看
PIL(http://www.pythonware.com/products/pil/)中包含很多图形处理库,主要是Image,Image库中包含三个类(Image、ImagePointHandler、ImageTransformHandler)及若干方法。
今天实验了一把,打开两个差异很小的图片,将其中一个反色处理,然后在将两个图像混合,就能比较清晰的看到差异的地方。
唔~~~~,这要是扩展一下,增加截图功能,可以做成“大家来找茬”之类游戏的作弊器了!!阿门~~~
代码如下:
原始图片如下:
1.bmp
2.bmp
混合后结果:
附:PIL.Image库说明文档
# 2009-11-15 fl PIL release 1.1.7
今天实验了一把,打开两个差异很小的图片,将其中一个反色处理,然后在将两个图像混合,就能比较清晰的看到差异的地方。
唔~~~~,这要是扩展一下,增加截图功能,可以做成“大家来找茬”之类游戏的作弊器了!!阿门~~~
代码如下:
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
混合后结果:
附:PIL.Image库说明文档
PIL.Image |
Classes | ||||||||||||||
ImageImagePointHandlerImageTransformHandler
|
Functions | ||
blend(im1, im2, alpha) Interpolate between images.将两张图片混合到一起。参数alpha是im1与im2的混合权重,范围为[0,1] composite(image1, image2, mask)Create composite image by blending images using a transparency mask eval(image, *args) Evaluate image expression fromarray(obj, mode=None) frombuffer(mode, size, data, decoder_name='raw', *args)Load image from string or buffer fromstring(mode, size, data, decoder_name='raw', *args)Load image from string getmodebandnames(mode) getmodebands(mode) getmodebase(mode) getmodetype(mode) init() Load all file format drivers. isDirectory(f) isImageType(t) isNumberType(...) isNumberType(a) -- Return True if a has a numeric type, False otherwise. isSequenceType(...) isSequenceType(a) -- Return True if a has a sequence type, False otherwise. isStringType(t) ## # (Internal) Checks if an object is a string. If the current # Python version supports Unicode, this checks for both 8-bit # and Unicode strings. isTupleType(t) merge(mode, bands) Merge a set of single band images into a new multiband image. new(mode, size, color=0)Create a new image创建一个Image对象 open(fp, mode='r')Open an image file, without loading the raster data打开图片文件 preinit() Load standard file format drivers. register_extension(id, extension) register_mime(id, mimetype) register_open(id, factory, accept=None) register_save(id, driver) |
相关文章推荐
- 使用Python+PIL查看两张相似图形的差异
- python3.x和python2.x的translate与maketrans函数使用差异
- python使用PIL缩放网络图片并保存的方法
- python使用pil库实现图片合成实例代码
- 用Python做图像处理(PIL库的使用)
- [转]Python 之 使用 PIL 库做图像处理
- Python 中使用PIL中的resize 进行缩放
- Python中使用PIL库实现图片高斯模糊实例
- 使用Python保存屏幕截图(不使用PIL)
- python使用PIL库做图像处理
- 小工具-查看某个python函数的使用说明
- Python 之 使用 PIL 库做图像处理
- python2学习笔记之查看API接口、http的使用
- Python 之 使用 PIL 库做图像处理
- 使用IntelliJ IDEA查看类的继承关系图形
- Python 之 使用 PIL 库做图像处理
- Python3.4 PIL的使用
- Python+Opencv识别两张相似图片
- python使用PIL库报错,'NoneType' object has no attribute 'bands'
- Python 之 使用 PIL 库做图像处理