[/url]
PythonWare公司提供了免费的图像处理工具包PIL(Python Image Library),该软件包提供了基本的图像处理功能.PIL提供了丰富的功能模块:Image,ImageDraw,ImageEnhance,ImageFile等等。最常用到的模块是Image,ImageDraw,ImageEnhance这三个模块。
1,Image module
>>import Image
>>f = Image.open('t.jpg') #open image
>>f.save('s.jpg') #save image
>>f.resize((128,128),Image.BILINEAR).save('resize.jpg') #resize image
>>f.rotate(45).save('rotate.jpg') #rotate image
>>f.save('format.bmp') #convert format
>>print f.histogram() #print histogram
2,ImageDraw
>>import Image,ImageDraw
>>f = Image.open('t.jpg') #plot circle
>>width,height = f.size
>>ImageDraw.Draw(f).arc((0,0,width-1,height-1),0,360,fill=255)
>>f.save('cricle.jpg')
3,ImageEnhance
>>import Image,ImageEnhance
>>f = Image.open('t.jpg')
>>ff = ImageEnhance.Brightness(f)
>>fff =ff.enhance(2.0)
>>f.save('bright.jpg') #enhance brightness
>>ImageEnhance.Sharpness(f).enhance(7.0).save('sharpness.jpg') #enhance sharpness
>>ImageEnhance.Contrast(f).enhance(2.0).save('contrast.jpg') #enhance constrast
1,本文基本上是一篇摘要,是关于《用Python进行图像处理》一文的笔记。
[url=http://so.zhuaxia.com/item/386086750]http://so.zhuaxia.com/item/386086750
2,http://tech.seety.org/python/python_imaging.html
3,pil-handbook里有更多精彩的例子
http://www.pythonware.com/products/pil/