PIL:Concepts 关于PIL的通道Bands,颜色模式Mode和滤波器Filters


Link to PIL: Concepts

Concepts

关于PIL的通道Bands,颜色模式Mode和滤波器Filters的介绍

Bands 通道


An image can consist of one or more bands of data. The Python Imaging Library allows you to store several bands in a single image, provided they all have the same dimensions and depth.

一个图像拥有一个或者多个通道,每个通道的维度和深度都是相同的。

To get the number and names of bands in an image, use the getbands method.

可以使用 getband() 方法来得到图像的通道名称

Mode 颜色模式

The mode of an image defines the type and depth of a pixel in the image. The current release supports the following standard modes:

图像的颜色模式:

  • 1 (1-bit pixels, black and white, stored with one pixel per byte)
  • L (8-bit pixels, black and white),8位灰度图
  • P (8-bit pixels, mapped to any other mode using a colour palette),8位彩色图,含调色板
  • RGB (3x8-bit pixels, true colour),24位彩色图
  • RGBA (4x8-bit pixels, true colour with transparency mask),32位彩色图,含alpha通道
  • CMYK (4x8-bit pixels, colour separation),32位彩色,即印刷四色模式,印刷颜色模型
  • YCbCr (3x8-bit pixels, colour video format),24位彩色,视频颜色格式
  • I (32-bit signed integer pixels),32位有符号整型
  • F (32-bit floating point pixels),32位浮点数

Filters 滤波器

For geometry operations that may map multiple input pixels to a single output pixel, the Python Imaging Library provides four different resampling filters.

这里介绍的滤波器和我们并非我们熟悉的卷积操作的相关模板,但是本质上是类似的:即将多个像素值映射到一个像素值的过程,PIL 为我们提供了四个滤波器:

  • NEAREST 最近邻插值
    取目标像素映射到原来图像位置上最邻近的像素的值

  • BILINEAR 双线性插值
    取映射回原来图像的位置最邻近的四个像素(2x2)进行双线性插值

  • BICUBIC 双三次插值
    原理和双线性插值类似,这里不细讲

  • ANTIALIAS 抗锯齿
    (New in PIL 1.1.3). Calculate the output pixel value using a high-quality resampling filter (a truncated sinc) on all pixels that may contribute to the output value. In the current version of PIL, this filter can only be used with the resize and thumbnail methods.
    这个滤波器使用一个高质量的重采样函数(一个截断的sinc函数),运用到所有可能对结果产生的所有像素上,计算出输出的最终像素值,实现抗锯齿的效果。当前版本中主要用于重新调整大小以及缩略图的生成

Note that in the current version of PIL, the ANTIALIAS filter is the only filter that behaves properly when downsampling (that is, when converting a large image to a small one). The BILINEAR and BICUBIC filters use a fixed input environment, and are best used for scale-preserving geometric transforms and upsamping.

在当前版本中,ANTIALIAS 的效果是最好的(但是速度较慢),而BILINEARBICUBIC只在比例保持的前提下拥有较好的效果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值