您的位置:首页 > 理论基础

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()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: