Java知识分享网 - 轻松学习从此开始!    

Java知识分享网

Java1234官方群25:java1234官方群17
Java1234官方群25:838462530
        
SpringBoot+SpringSecurity+Vue+ElementPlus权限系统实战课程 震撼发布        

最新Java全栈就业实战课程(免费)

springcloud分布式电商秒杀实战课程

IDEA永久激活

66套java实战课程无套路领取

锋哥开始收Java学员啦!

Python学习路线图

锋哥开始收Java学员啦!
当前位置: 主页 > Java文档 > Java基础相关 >

Python Imaging Library Overview PDF 下载


分享到:
时间:2020-09-16 09:28来源:http://www.java1234.com 作者:小锋  侵权举报
Python Imaging Library Overview PDF 下载
失效链接处理
Python Imaging Library Overview PDF 下载

本站整理下载:
 
相关截图:
 
主要内容:

Introduction
The Python Imaging Library adds image processing capabilities to your Python
interpreter.
This library provides extensive file format support, an efficient internal representation,
and fairly powerful image processing capabilities.
The core image library is designed for fast access to data stored in a few basic pixel
formats. It should provide a solid foundation for a general image processing tool.
Let's look at a few possible uses of this library:
Image Archives
The Python Imaging Library is ideal for for image archival and batch processing
applications. You can use the library to create thumbnails, convert between file formats,
print images, etc.
The current version identifies and reads a large number of formats. Write support is
intentionally restricted to the most commonly used interchange and presentation formats.
Image Display
The current release includes Tk PhotoImage and BitmapImage interfaces, as well as a
Windows DIB interface that can be used with PythonWin. For X and Mac displays, you can
use Jack Jansen's img library.
For debugging, there's also a show method in the Unix version which calls xv to display the
image.
Image Processing
The library contains some basic image processing functionality, including point operations,
filtering with a set of built-in convolution kernels, and colour space conversions.
The library also supports image resizing, rotation and arbitrary affine transforms.
There's a histogram method allowing you to pull some statistics out of an image. This can
be used for automatic contrast enhancement, and for global statistical analysis.
Tutorial
Using the Image Class
The most important class in the Python Imaging Library is the Image class, defined in the
module with the same name. You can create instances of this class in several ways; either
by loading images from files, processing other images, or creating images from scratch.
To load an image from a file, use the open function in the Image module.
>>> import Image
>>> im = Image.open("lena.ppm")
If successful, this function returns an Image object. You can now use instance attributes
to examine the file contents.
>>> print im.format, im.size, im.mode
PPM (512, 512) RGB
The format attribute identifies the source of an image. If the image was not read from a
file, it is set to None. The size attribute is a 2-tuple containing width and height (in
pixels). The mode attribute defines the number and names of the bands in the image, and
also the pixel type and depth. Common modes are "L" (luminance) for greyscale images,
"RGB" for true colour images, and "CMYK" for pre-press images.
If the file cannot be opened, an IOError exception is raised.
Once you have an instance of the Image class, you can use the methods defined by this
class to process and manipulate the image. For example, let's display the image we just
loaded:
 >>> im.show()
(The standard version of show is not very efficient, since it saves the image to a
temporary file and calls the xv utility to display the image. If you don't have xv installed,
it won't even work. When it does work though, it is very handy for debugging and tests.)
The following sections provide an overview of the different functions provided in this
library.
Reading and Writing Images
The Python Imaging Library supports a wide variety of image file formats. To read files
from disk, use the open function in the Image module. You don't have to know the file
format to open a file. The library automatically determines the format based on the
contents of the file.
To save a file, use the save method of the Image class. When saving files, the name
becomes important. Unless you specify the format, the library uses the filename extension
to discover which file storage format to use.
Example: Convert files to JPEG
import os, sys
import Image
for infile in sys.argv[1:]:
 outfile = os.path.splitext(infile)[0] + ".jpg"
 if infile != outfile:
 try:
 Image.open(infile).save(outfile)
 except IOError:
 print "cannot convert", infile
A second argument can be supplied to the save method which explicitly specifies a file
format. If you use a non-standard extension, you must always specify the format this way:
Example: Create JPEG Thumbnails
import os, sys
import Image
for infile in sys.argv[1:]:
 outfile = os.path.splitext(infile)[0] + ".thumbnail"
 if infile != outfile:
 try:
 im = Image.open(infile)
 im.thumbnail((128, 128))
 im.save(outfile, "JPEG")
 except IOError:
 print "cannot create thumbnail for", infile
It is important to note is that the library doesn't decode or load the raster data unless it
really has to. When you open a file, the file header is read to determine the file format
and extract things like mode, size, and other properties required to decode the file, but
the rest of the file is not processed until later.
This means that opening an image file is a fast operation, which is independent of the file
size and compression type. Here's a simple script to quickly identify a set of image files:
Example: Identify Image Files
import sys
import Image
for infile in sys.argv[1:]:
 try:
 im = Image.open(infile)
 print infile, im.format, "%dx%d" % im.size, im.mode
 except IOError:
 pass

 

------分隔线----------------------------

锋哥公众号


锋哥微信


关注公众号
【Java资料站】
回复 666
获取 
66套java
从菜鸡到大神
项目实战课程

锋哥推荐