没有合适的资源?快使用搜索试试~ 我知道了~
首页Python图像处理库指南Python Imaging Library(PIL) Guide
Python Imaging Library (PIL) Document from New Mexico Tech.Describes an image-processing library for the Python programming language.
资源详情
资源评论
资源推荐
Python Imaging Library
(PIL)
John W. Shipman
2009-05-01 16:47
Abstract
Describes an image-processing library for the Python programming language.
This publication is available in Web form
1
and also as a PDF document
2
. Please forward any
comments to tcc-doc@nmt.edu.
Table of Contents
1. Introduction ............................................................................................................................ 1
2. Definitions .............................................................................................................................. 2
2.1. Band ............................................................................................................................. 2
2.2. Modes .......................................................................................................................... 2
2.3. Sizes ............................................................................................................................. 2
2.4. Coordinates .................................................................................................................. 2
2.5. Angles .......................................................................................................................... 2
2.6. Bboxes (bounding boxes) ................................................................................................ 3
2.7. Colors ........................................................................................................................... 3
2.8. Filters ........................................................................................................................... 3
3. Creating objects of class Image ................................................................................................. 4
3.1. Attributes of the Image object ........................................................................................ 4
3.2. Methods on the Image object ......................................................................................... 5
4. The ImageDraw module .......................................................................................................... 8
5. Image enhancement: the ImageFilter module ........................................................................ 9
6. The ImageFont module ........................................................................................................ 10
7. The ImageTk module ............................................................................................................. 10
8. Supported file formats ............................................................................................................ 11
1. Introduction
The Python Imaging Library (PIL) allows you to create, modify, and convert image files in a wide
variety of formats using the Python language.
For additional PIL features not described in this document, refer to the online PIL handbook
3
.
For more information about Python, refer to the author's companion publication, Python programming
language quick reference
4
, or to the Python Web site
5
, for general information about the Python language.
1
http://www.nmt.edu/tcc/help/pubs/pil/
2
http://www.nmt.edu/tcc/help/pubs/pil/pil.pdf
3
http://www.pythonware.com/library/pil/handbook/index.htm
4
http://www.nmt.edu/tcc/help/pubs/python22/
5
http://www.python.org/
1Python Imaging Library (PIL)New Mexico Tech Computer Center
2. Definitions
These terms are used throughout:
2.1. Band
An image band is a set of values, one per image pixel. Monochrome or grayscale images have one band;
color images in the RGB system have three bands, CMYK images have four, and so on. Photoshop users
will recognize bands as similar to Photoshop channels.
2.2. Modes
The mode of an image describes the way it represents colors. Each mode is represented by a string:
DescriptionBandsMode
Black and white (monochrome), one bit per pixel.1
"1"
Gray scale, one 8-bit byte per pixel.1
"L"
Palette encoding: one byte per pixel, with a palette of class ImagePalette
translating the pixels to colors. This mode is experimental; refer to the online
documentation
6
.
1
"P"
True red-green-blue color, three bytes per pixel.3
"RGB"
True color with a transparency band, four bytes per pixel, with the A channel
varying from 0 for transparent to 255 for opaque.
4
"RGBA"
Cyan-magenta-yellow-black color, four bytes per pixel.4
"CMYK"
Color video format, three 8-bit pixels.3
"YCbCr"
32-bit integer pixels.1
"I"
32-bit float pixels.1
"F"
2.3. Sizes
The sizes of objects in the image are described as a 2-tuple (w, h), where h is the height in pixels and
w is the width.
2.4. Coordinates
The coordinates of a pixel are of its upper left corner. Point (0,0) is the upper left corner of the image.
The x coordinate increases to the right, and the y coordinate increases downward.
When directions are given as compass points such as east or southwest, assume north is up, toward the
top of the display.
2.5. Angles
Angles are given in degrees. Zero degrees is in the +x (east) direction, and the angle increases counter-
clockwise, in the usual Cartesian convention. For example, angle 45 points northeast.
6
http://www.pythonware.com/library/pil/handbook/index.htm
New Mexico Tech Computer CenterPython Imaging Library (PIL)2
2.6. Bboxes (bounding boxes)
A bounding box or bbox is a rectangle in the image. It is defined by a 4-tuple, (x
0
, y
0
, x
1
, y
1
) where (x
0
,
y
0
) is the top left (northwest) corner of the rectangle, and (x
1
, y
1
) is the bottom right (southeast) corner.
Generally, the area described by a bounding box will include point (x
0
, y
0
), but it will not include point
(x
1
, y
1
) or the row and column of pixels containing point (x
1
, y
1
).
For example, drawing an ellipse inside the bounding box (0,0,5,10) will produce an ellipse 5 pixels
wide and 10 pixels high. The resulting ellipse will include pixel column 4 but not column 5, and will
also include pixel row 9 but not row 10.
2.7. Colors
You can specify colors in several different ways.
•
For single-band images, the color is the pixel value. For example, in a mode "1" image, the color is
a single integer, 0 for black, 1 for white. For mode "L", it is an integer in the range [0,255], where 0
means black and 255 means white.
•
For multi-band images, supply a tuple with one value per band. In an "RGB" image, the tuple
(255,0,0) is pure red.
•
You can use CSS-style color name strings of the form #rrggbb, where rr specifies the red part as
two hexadecimal digits, gg specifies green, and bb blue. For example, "#ffff00" means yellow
(full red + full green).
•
To specify RGB pixel values in decimal, use a string of the form "rgb(R,G,B)". For example,
"rgb(0,255,0)" is pure green.
•
To specify RGB pixel values as percentages, use a string of the form "rgb(R%,G%,B%)". For example,
you can get a light gray with "rgb(85%,85%,85%)".
• To specify colors in the hue-saturation-lightness (HSV) system, use a string of the form
"hsl(H,S%,L%)".
H is the hue angle in degrees: 0 is red, 60 is yellow, 120 is green, and so on.
S is the saturation: 0% for unsaturated (gray), 100% for fully saturated.
The lightness L is 0% for black, 50% for normal, and 100% for white.
For example, "hsl(180,100%,50%)" is pure cyan.
• On Unix systems, you can use any of the standard color names from the locally installed set given in
file "/usr/lib/X11/rgb.txt", such as "white", "DodgerBlue", or "coral".
2.8. Filters
Some operations that reduce the number of pixels, such as creating a thumbnail, can use different filters
to compute the new pixel values. These include:
NEAREST
Uses the value of the nearest pixel.
BILINEAR
Uses linear interpolation over a 2x2 set of adjacent pixels.
3Python Imaging Library (PIL)New Mexico Tech Computer Center
剩余11页未读,继续阅读
in7deforever
- 粉丝: 38
- 资源: 12
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- 数据结构1800题含完整答案详解.doc
- 医疗企业薪酬系统设计与管理方案.pptx
- 界面与表面技术界面理论与表面技术要点PPT学习教案.pptx
- Java集合排序及java集合类详解(Collection、List、Map、Set)讲解.pdf
- 网页浏览器的开发 (2).pdf
- 路由器原理与设计讲稿6-交换网络.pptx
- 火电厂锅炉过热汽温控制系统设计.doc
- 企业识别CIS系统手册[收集].pdf
- 物业管理基础知识.pptx
- 第4章财务预测.pptx
- 《集成电路工艺设计及器件特性分析》——实验教学计算机仿真系.pptx
- 局域网内共享文件提示没有访问权限的问题借鉴.pdf
- 第5章网络营销策略.pptx
- 固井质量测井原理PPT教案.pptx
- 毕业实习总结6篇.doc
- UGNX建模基础篇草图模块PPT学习教案.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论2