Python计算机视觉Learning(二)-- Matplotlib类库
2016-07-26 14:19
501 查看
Matplotlib类库具有比PIL更强大的绘图功能,其中的PyLab接口包含了很多方便用户创建图像的函数。Matplotlib同样是个开源库,下载链接
绘制图像,点和线
from PIL import Image
form pylab import *
#绘制图像
#读取图像到数组
img = array(Image.open('lena.jpg'))
imshow(img)
#绘制点
x=[200,200,500,500]
y=[250,650,250,650]
plot(x,y,'g*')
#绘制线(链接两个点)
plot(x[:2],y[:2])
title('show the plot')
show()
注意:在每个脚本里,只能调用一次show(),并且通常在结尾;另外同Opencv一样坐标原点为左上角。
绘制轮廓
from PIL import Image
from pylab import *
img = array(Iamge.open('lena.jpg').convert('L')
#新建一个图像
figure()
#不使用颜色信息
gray()
#绘制轮廓
contour(img,origin='image')
绘制直方图
figure()
hist(img.flatten(),128)
show()其中,flatten()函数可以将任意数组按照行优先的原则转成一维数组;
交互式标注
ginput()函数可以实现用户交互,例如我想要在图像上选取两个兴趣点:
img = array(Image.open('lena.jpg'))
imshow(img)
print 'please enter 2 points'
x = ginput(2)
print 'you entered: ',x
show()
绘制图像,点和线
from PIL import Image
form pylab import *
#绘制图像
#读取图像到数组
img = array(Image.open('lena.jpg'))
imshow(img)
#绘制点
x=[200,200,500,500]
y=[250,650,250,650]
plot(x,y,'g*')
#绘制线(链接两个点)
plot(x[:2],y[:2])
title('show the plot')
show()
注意:在每个脚本里,只能调用一次show(),并且通常在结尾;另外同Opencv一样坐标原点为左上角。
绘制轮廓
from PIL import Image
from pylab import *
img = array(Iamge.open('lena.jpg').convert('L')
#新建一个图像
figure()
#不使用颜色信息
gray()
#绘制轮廓
contour(img,origin='image')
绘制直方图
figure()
hist(img.flatten(),128)
show()其中,flatten()函数可以将任意数组按照行优先的原则转成一维数组;
交互式标注
ginput()函数可以实现用户交互,例如我想要在图像上选取两个兴趣点:
img = array(Image.open('lena.jpg'))
imshow(img)
print 'please enter 2 points'
x = ginput(2)
print 'you entered: ',x
show()
相关文章推荐
- [计算机网络]--代理服务器原理
- Web缓存基础:术语、HTTP报头和缓存策略
- http长/短轮询和WebSocket 的介绍和比较
- nginx配置ssl加密(单双向认证、部分https)
- iOS NSURLSession 网络请求 重定向 302
- 采集温度和时间网络上报
- SNMP网络管理协议,企业对应的OID段
- 【数据结构】单链表—寻找两个相交链表中第一个公共结点 — 蛮力法 / 栈 / 指针先走
- 网络爬虫项目开发日志(二):爬虫架构设计
- 有序顺序表的查询
- fiddler-实现https抓包
- 黑客攻防入门(一)缓冲区(堆栈)溢出
- [计算机网络]--NAT原理介绍
- 【数据结构】单链表—合并两个排序链表 — 递归
- 【数据结构】单链表—在O(1)时间删除链表结点
- TCP连接的建立与中止
- linux下C发送HttpPost请求
- 元素位置互换之逆置算法
- 元素位置互换之移位算法
- 多余元素删除之建表算法