PIL与matplotlib的图形显示
来源:互联网 发布:软件报价怎么描述 编辑:程序博客网 时间:2024/06/05 16:21
# -*-coding:utf8-*-import matplotlib.pyplot as plt import matplotlib.image as mpimg # 用于读取图片filename = 'C:\\Users\\i\\Desktop\\10.jpg'# lena1 = mpimg.imread(filename) # 这里读取后,即为numpy格式# plt.imshow(lena1)# plt.savefig('C:\\Users\\i\\Desktop\\11.jpg') # 图片保存import numpy as np from scipy import misc # 在下面可以实现图片的缩放from PIL import Image im = Image.open(filename)# 这里读取后需要转为 numpy 后,才可以实现对数组的操作#im.save('C:\\Users\\i\\Desktop\\11.jpg') # 图片保存plt.subplot(141)r,g,b=im.split() # 三通道分离plt.title('r通道显示',fontproperties='SimHei')plt.imshow(r,cmap='gray')plt.axis('off') plt.subplot(142)im1 = im.crop([50,50,150,300]) # 图片剪切im1 = im1.rotate(0) # 图片顺时针旋转 0°plt.title('图片剪切与缩放',fontproperties='SimHei')plt.imshow(im1) # 显示图片plt.axis('off') # 关闭坐标轴 #im1.show() # 会直接显示出来#im1 = np.array(im1) # 将图片转为numpy数组plt.subplot(143)a = np.random.randint(0,255,(480,288,3))a = Image.fromarray(np.uint8(a)) # 将数组转为PIL图片,图片的a.dtype = uint8, 否则无法显示plt.title('自定义a的图像',fontproperties='SimHei')plt.imshow(a)plt.axis('off')plt.subplot(144)lena = misc.imresize(im, 10) # 对图片的缩放到10%#lena_new_sz = misc.imresize(im, (60,36,3)) # 直接修改图片的尺寸,达到缩减的目的plt.title(u'缩放后的图像',fontproperties='SimHei') # 设置字体,否则中文会乱码lena = Image.fromarray(np.uint8(lena)) # 将数组转为PIL图片,这样才有 convert 模块lena = lena.convert('L') # 设置灰度plt.imshow(lena,cmap = 'gray')plt.axis('off')plt.show()#im.show()
0 0
- PIL与matplotlib的图形显示
- Python 图形库 PIL, matplotlib 显示中文
- Jupyter中直接显示Matplotlib的图形
- CentOS下matplotlib的安装中图形显示问题
- centos 安装python的PIL matplotlib模块
- matplotlib实现交换式图形显示
- 演示如何实现Matplotlib绘图并保存图像但不显示图形的方法
- 演示如何实现Matplotlib绘图并保存图像但不显示图形的方法
- 演示如何实现Matplotlib绘图并保存图像但不显示图形的方法
- PIL与Reportlab的安装
- PIL的编译与安装
- Python、Numpy、Matplotlib、PIL安装
- python PIL 图形操作
- python的NumPy数学库和Matplotlib图形库的安装与配置
- matplotlib 图形中线条的设置。
- 使用 Matplotlib 绘制精美的数学图形
- 实时Log信息,图形化显示(Python matplotlib)
- matplotlib画图时调用多线程关闭图形显示
- mybatis中的@Param
- IOS系统基础
- 无线路由器信道干扰事件
- v-for循环 重复数据无法添加问题
- Android CardView使用问题记录
- PIL与matplotlib的图形显示
- Android 相关七种 CPU 架构适配
- Java 中extends与implements使用方法
- OpenWRT基础
- 某企业广域网BGP拓扑图
- 7065233排队
- HTTP协议
- BZOJ 1444: [Jsoi2009]有趣的游戏 AC自动机加矩阵快速幂
- 解决python2.x 的UnicodeDecodeError