用PIL库进行图像处理
一、如果系统里没有安装PIL库的,请先到命令提示符输入“pip install pillow”进行安装
二、之后就可以参考以下的代码
from PIL import Image
from pylab import * # 添加中文字体支持
from matplotlib.font_manager import FontProperties
font = FontProperties(fname=r"c:\windows\fonts\SimSun.ttc", size=14)
figure() pil_im = Image.open('E:\python\Python Computer Vision\Image data\empire.jpg')
gray()
subplot(121)
title(u'原图',fontproperties=font)
axis('off')
imshow(pil_im) pil_im = Image.open('E:\python\Python Computer Vision\Image data\empire.jpg').convert('L')
subplot(122)
title(u'灰度图',fontproperties=font)
axis('off')
imshow(pil_im) show()
三,可以观看效果
四、其还可以进行旋转等操作
from PIL import Image
from pylab import * # 添加中文字体支持
from matplotlib.font_manager import FontProperties font = FontProperties(fname=r"c:\windows\fonts\SimSun.ttc", size=14)
figure() # 显示原图
pil_im = Image.open('E:/python/Python Computer Vision/Image data/empire.jpg')
print(pil_im.mode, pil_im.size, pil_im.format)
subplot(231)
title(u'原图', fontproperties=font)
axis('off')
imshow(pil_im) # 显示灰度图
pil_im = Image.open('E:/python/Python Computer Vision/Image data/empire.jpg').convert('L')
gray()
subplot(232)
title(u'灰度图', fontproperties=font)
axis('off')
imshow(pil_im) # 复制并粘贴区域
pil_im = Image.open('E:/python/Python Computer Vision/Image data/empire.jpg')
box = (100, 100, 400, 400)
region = pil_im.crop(box)
region = region.transpose(Image.ROTATE_180)
pil_im.paste(region, box)
subplot(233)
title(u'复制粘贴区域', fontproperties=font)
axis('off')
imshow(pil_im) # 缩略图
pil_im = Image.open('E:/python/Python Computer Vision/Image data/empire.jpg')
size = 128, 128
pil_im.thumbnail(size)
print(pil_im.size)
subplot(234)
title(u'缩略图', fontproperties=font)
axis('off')
imshow(pil_im)
pil_im.save('E:/python/Python Computer Vision/Image data/empire thumbnail.jpg')# 保存缩略图 #调整图像尺寸
pil_im=Image.open('E:/python/Python Computer Vision/Image data/empire thumbnail.jpg')
pil_im=pil_im.resize(size)
print(pil_im.size)
subplot(235)
title(u'调整尺寸后的图像',fontproperties=font)
axis('off')
imshow(pil_im) #旋转图像45°
pil_im=Image.open('E:/python/Python Computer Vision/Image data/empire thumbnail.jpg')
pil_im=pil_im.rotate(45)
subplot(236)
title(u'旋转45°后的图像',fontproperties=font)
axis('off')
imshow(pil_im) show()
查看效果:
用PIL库进行图像处理的更多相关文章
- Python 之 使用 PIL 库做图像处理
http://www.cnblogs.com/way_testlife/archive/2011/04/17/2019013.html Python 之 使用 PIL 库做图像处理 1. 简介. 图像 ...
- [转]Python 之 使用 PIL 库做图像处理
Python 之 使用 PIL 库做图像处理 1. 简介. 图像处理是一门应用非常广的技术,而拥有非常丰富第三方扩展库的 Python 当然不会错过这一门盛宴.PIL (Python Imaging ...
- PIL库,图像处理第三方库
PIL ---> python imaging library 安装需要安装pillow库,包含了21种类,其中Image类是PIL最重要的一个类,可以通过它来处理图像. Python最常用的 ...
- python爬虫基础15-python图像处理,PIL库
Python图像处理-Pillow 简介 Python传统的图像处理库PIL(Python Imaging Library ),可以说基本上是Python处理图像的标准库,功能强大,使用简单. 但是由 ...
- python图像处理之PIL库
PIL库是python语言第三方库,需要通过pip工具安装,安装库的名字是pillow. PIL库支持图像存储,显示和处理,它能够处理几乎所有图片格式,可以完成对图像的缩放,裁剪,叠加以及向图像添加线 ...
- PIL库图像处理
PIL有如下几个模块 Image模块.ImageChops模块.ImageCrackCode模块 ImageDraw模块.ImageEnhance模块.ImageFile模块 ImageFileIO模 ...
- 一秒钟带你走进P图世界-----(python)PIL库的使用
python-----PIL库的使用 一.什么是PIL库 1.PIL(Python Image Library)库是python语言的第三方库,具有强大的图像处理能力,不仅包含了丰富的像素.色彩操作功 ...
- python之PIL库(Image模块)
PIL(Python Image Library)是python的第三方图像处理库,PIL的功能非常的强大,几乎被认定是Python的官方图像处理库了. 由于PIL仅支持到python2.7于是一群志 ...
- 玩转PIL库
1.安装pillow库: 在cmd下,输入简单的命令: pip install pillow 即可安装pillow库. 2.PIL库的简介: 1. PIL库主要有2个方面的功能: (1) 图像归档: ...
随机推荐
- NetBeans GUI tests on Jenkins + Windows (转)
from http://forgetfulprogrammer.wordpress.com/tag/interact-with-desktop/ Running NetBeans applicatio ...
- MTCP 在 64 位机器上不工作
今天打开以前写的 MTCP, 却无法运行. 报错如下: Exception in thread "Thread-0" java.lang.UnsatisfiedLinkError: ...
- Linux和Shell教程
文档资料参考: 参考:http://www.runoob.com/linux/linux-tutorial.html 软件下载参考: centos 下载地址:https://www.centos.or ...
- nvwgf2umx.dll 显卡崩溃问题尝试修复
问题背景 游戏上线之后,搜集到的奔溃列表里面列表存在大量的显卡驱动异常崩溃,window在vista之后,将显卡驱动模型从Xpdm改为了WDDM. WDDM的说明详见百度百科,其中最主要的变更如下: ...
- RMAN备份filesperset用法
用filesperset控制备份集的尺寸 当指定filesperset参数时,rman比较filesperset与自动计算出来的值(对每个已分配通道的文件数目) 并取其中较小的那个值来保证所有的通道被 ...
- 用servlet进行用户名和密码校验1
运行效果如下: 代码截图: 登陆网页: 显示网页: 网盘链接: 链接:https://pan.baidu.com/s/1g5XJ6y8u5R5Wt0Lkj9g9lg 提取码:bphb
- Tkinter 项目-屏保
参考教程,以及网上资料,针对小白更好理解 关于tkinter的屏保涉及的知识点和思想 项目分析: 屏保启动方式:手动,自动 敲击键盘或者移动鼠标后,或者其他引发事件,则停止 如果屏保是一幅画的话,则没 ...
- atmega16功耗实测
晶振32.768K 电压 电流 1.82 10ua 2.00 15ua 2.5 28ua 3.3 ...
- [LeetCode] 70. Climbing Stairs_ Easy tag: Dynamic Programming
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- 个人对stm32ADC编程关键点的理解
平时在做项目或者参加比赛的过程中,个人觉得,有些东西写出来可能会帮助到新手少走弯路.(也很可能是错误的,欢迎大家纠错) 如果只是采集一路信号,直接用ADC独立模式,单通道就可以了. 如果需要同时采集多 ...