Introduction to Python image processing PiL library

Source: Internet
Author: User

Moving from my blog:http://www.xgezhang.com/python_pil.html

Recently used some simple image processing, here is a brief introduction, Python Imaging Library (PIL) is Pythonware Company provides a free image processing toolkit, is a Python image processing module, support a variety of formats, and provides powerful graphics and image processing capabilities. While it is not appropriate to implement complex image processing algorithms like MATLAB in this package, Python's rapid development capabilities and object-oriented features make it a great fit for prototyping. Python+pil is a good choice for simple image processing or large-scale, simple image processing tasks.

PIL has the following capabilities (but not limited to):

    • number Span style= "line-height:1.5" > 10 graphic file format reading and writing ability.
    • common jpeg, PNG, BMP, GIF, TIFF format, are in the PIL's support list.  
    • PIL also supports black-and-white, grayscale, custom palette, RGB True Color, RBG true Color with transparent properties, CMYK, and several other image modes.  
    • basic image data operations: crop, pan, rotate, resize, adjust (transpose), cut and paste and so on.  
    • Enhanced graphics: brightness, hue, contrast, sharpness.  
    • color processing.  

Here are some basic usage methods, after importing the image Library of PIL, we first open a picture, using the function:

?
1 img=Image.open(‘filename‘)

View picture formats, sizes, modes, and more, and view pictures:

?
1234 printimg.formatprintimg.sizeprintimg.modeimg.show()

Format conversion is very simple, just want to pass Img.save ("Xxx.bmp"), you can convert the previous format of the diagram into BMP format, but the function of the Save function itself is to save a temporary picture file, and the format conversion function is implemented by the CONVERT () function:

We can crop the chunks that specify the location of the image, for example, the position of the coordinates (100,100) to the lower right (400,400) Section:

?
12 region = 100 , 100 400 400 ) = img.crop (region)

Geometric transformations, including changing dimensions, rotating:

?
123 out = img.resize ( 100 ) out Img.rotate ( 45 ) = Img.transpose (image.rotate_180)

We know that an image is divided into RGB three channels, the PIL library allows us to operate on a single channel, first we divide the value of 3 channels:

?
1234 r,g,b=img.split()#分割成三个通道  r.show() g.show() b.show()

Here are just a few basic usage, more see handbook:http://effbot.org/imagingbook/

Introduction to Python image processing PiL library

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.