PIL Python包的安装:sudo pip install Pillow
Image 模块是 PIL 图像处理的一个类,其提供了很多函数,包括图片加载,创建新图片等.
例如:
图片旋转 45 度:from PIL import Image
img = Image.open("test.jpg")
img.rotate(45).show() #旋转
创建缩略图(thumbnails):from PIL import Image
img = Image.open("test.jpg")
img.thumbnail((128, 128))
img.save("test.thumbnail", "JPEG")
图像 Mode 属性:1 - 1-bit 像素,黑和白,每个字节保存一个像素(1-bit pixels, black and white, stored with one pixel per byte)
L - 8-bit 像素 (8-bit pixels, black and white)
P - 8-bit 像素 (8-bit pixels, mapped to any other mode using a color palette 颜色调色板)
RGB - 3x8-bit 像素,真实颜色(3x8-bit pixels, true color)
RGBA - 4x8-bit 像素,真实颜色加上透明图 (4x8-bit pixels, true color with transparency mask)
CMYK - 4x8-bit 像素 (4x8-bit pixels, color separation)
YCbCr - 3x8-bit 像素 (3x8-bit pixels, color video format)
LAB - 3x8-bit 像素 (3x8-bit pixels, the L_a_b color space)
HSV - 3x8-bit 像素 (3x8-bit pixels, Hue, Saturation, Value color space)
I - 32-bit 带符号整数像素(32-bit signed integer pixels)
F - 32-bit 浮点数像素 (32-bit floating point pixels)
图像 Filters 属性:
多个输入像素映射到单个输出像素的几何操作.
四种不同像素重采样 filters:NEAREST - 选择输入图像的最近像素;忽略其它输入像素.
BILINEAR - 图片 resize 时,对所有对输出值相关的所有像素进行线性插值,以得到输出像素;线性插值时,采用对输入图像 2x2 的区域.
BICUBIC - 图片 resize 时,对所有对输出值相关的所有像素进行三次插值,以得到输出像素;线性插值时,采用对输入图像 4x4 的区域.
LANCZOS - 对所有对输出值相关的所有像素采用高质量的 Lanczos filter(截断正弦) 进行插值,以得到输出像素;当前 PIL 版本,其仅用于 resize 和 thumbnail 方法.
图像坐标系统