美文网首页
PIL基本操作

PIL基本操作

作者: 此番风景 | 来源:发表于2017-12-24 09:41 被阅读50次

PIL: python图像处理类库

PIL(Python Imaging Library Python,图像处理类库)提供了通用的图像处理功能,
以及大量有用的基本图像操作,比如图像缩放、裁剪、旋转、颜色转换等。PIL 是
免费的,可以从 http://www.pythonware.com/products/pil/ 下载

打开图像

pil_im = Image.open('image_path')

颜色转换

pil_im.convert('L')

转换图像格式

通过save()方法,将图像保存成多种格式的文件。从文件名列表中读取所有图像文件,转换为JPEG格式.

from PIL import Image
import os

for infile in filelist:
    outfile = os.path.splitext(infile)[0] + '.jpg'  # splitext截取后缀
    if infile != outfile:
        try:
            Image.open(infile).save(outfile)
        except IOError:
            print("cannot convert", infile)

创建缩略图

pil_im.thumbnail((128, 128))

复制和粘贴图像区域

box = (100,100,400,400)  # (left, up, right, down)
region = pil_im.crop(box)

# 旋转剪切区域,粘贴到同一个位置
region = region.transpose(Image.ROTATE_180)
pil_im.paste(region, box)

调整尺寸和旋转

调整大小
out=pil_im.resize((128,128))

旋转
out=pil_im.rotate(45)

相关文章

  • PIL基本操作

    PIL: python图像处理类库 PIL(Python Imaging Library Python,图像处理类...

  • PyTorch之torchvision.transforms

    参考:【pytorch】图像基本操作 PIL transforms.ToTensor() 注意:transform...

  • 图像基本操作:PIL,Matplotlib

    PIL:Python图像处理类库 PIL安装 读取一幅图像 转换图像格式 创建一个包含文件夹中所有图像文件的文件名...

  • 常用的图像处理库

    (1)PIL库 PIL 是通用的python 图像处理库,可实现基本的图像缩放、裁剪、旋转和颜色转换等操作。其最重...

  • python 操作图片

    python中操作图片,需要使用PIL模块, ··这个模块包含在pillow模块中,要使用文件操作,需要安装pil...

  • 2018-06-23

    PIL的基本概念介绍: PIL中所涉及的基本概念有如下几个:通道(bands)、模式(mode)、尺寸(size)...

  • PIL操作总结

    1.读写open(路径)save(路径)show()https://www.cnblogs.com/sun-hai...

  • PIL图像操作

    安装 Mac和其他版本的Linux可以直接使用easy_install或pip安装,安装前需要把编译环境装好: 如...

  • (9) python PIL

    (一)PIL(python image library)的基本概念 PIL中主要涉及几个概念:通道、模式、尺寸、坐...

  • PIL的常用操作

    (一)PIL(python image library)的基本概念 PIL中主要涉及几个概念:通道、模式、尺寸、坐...

网友评论

      本文标题:PIL基本操作

      本文链接:https://www.haomeiwen.com/subject/oricgxtx.html