pil python图像处理模块

pil python图像处理模块

ID:20549251

大小:349.00 KB

页数:14页

时间:2018-10-12

pil python图像处理模块_第1页
pil python图像处理模块_第2页
pil python图像处理模块_第3页
pil python图像处理模块_第4页
pil python图像处理模块_第5页
资源描述:

《pil python图像处理模块》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、PythonImageLibrary PIL10/13/05PIL–Whatisit?PythoniclibraryforLoadingandSavingimages(diverseformats)Scaling,cropping,compositing,transforms,bands(e.g.alphachannel)DrawingtextandbasicshapesAkintotheprogramGIMP(*GIMPalsohasanicepythonAPIcalledGIMP-Python)PIL-ExamplesImageresi

2、zingorformatconversionsAddingsave/loadsupportintoyourapplication*FontsupportalsohandyChartgeneration(alsoseePIDDLEpiddle.sf.net)ThumbnailgenerationWatermarkingoraddinglegendPILAPI-ConceptsImage–fromfileornewlycreated>>>importImage>>>im=Image.open(“vacation.jpeg")>>>newIm=I

3、mage.new(“RGBA”,(640,480),(255,0,0))Format–fileformat>>>printim.mode,im.size,im.formatRGB(1024,768)JPEG>>>im.save(“vacation.png”)OR>>>im.save(“vacation.png”,“PNG”)PILAPI-ConceptsResamplingFiltersNEAREST,BILINEAR,BICUBIC,ANTIALIAS>>>smallIm=im.resize((128,128),Image.ANTIALI

4、AS)Sizes–tupleofwidthandheightBoundingboxes–tuplesofx1,y1,x2,y20,0isalwaysupperleftPILAPI-ConceptsMode–grayscale“L”,color“RGBA”“RGB”,etc.1(1-bitpixels,blackandwhite,storedwithonepixelperbyte)L(8-bitpixels,blackandwhite)P(8-bitpixels,mappedtoanyothermodeusingacolourpalette)

5、RGB(3x8-bitpixels,truecolour)RGBA(4x8-bitpixels,truecolourwithtransparencymask)CMYK(4x8-bitpixels,colourseparation)YCbCr(3x8-bitpixels,colourvideoformat)I(32-bitintegerpixels)F(32-bitfloatingpointpixels)Color–specifiedas32bitvalue,tuple,orstringmyColor=(255,0,0,128)#fullre

6、d,with50%alphamyColor=0x7f0000ff#fullred,with50%alphamyColor=“#00ff00”#webcolormyColor=“rgb(75%,0%,0%)”myColor=“hsl(0,100%,50%)”PILAPI-ConceptsBands–theseparatecolorchannels>>>bands=im.split()>>>rIm=bands[0]>>>aIm=bands[3]>>>remadeImage=Image.merge(“RGBA”,(rIm,gIm,bIm,aIm)

7、)>>>grayscaleIm=Image.open(“myAlpha.gif”)>>>remadeImage=myImage.putalpha(grayscaleIm)#replacethealphabandPIL–Slicing&DicingThumbnailsModifiesin-placePreservesaspectratio>>>myImage.thumbnail((128,128),Image.ANTIALIAS)Crop>>>bounds=(100,100,400,400)>>>cutoutIm=myImage.crop(b

8、ounds)PastePIL–Slicing&DicingBlend/compositeRotateTransposeROTATE_90/180/270,FLIP_TOP_BOT

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。