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 |
print img. format print img.size print img.mode img.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