用Python的Matplotlib模块进行基本的图像操作

来源:互联网 发布:sqlserver删除表字段 编辑:程序博客网 时间:2024/06/08 10:04
#Matplotlib的相关使用
from PIL import Image
from pylab import *
#array()以数组形式读取图像
im=array(Image.open('testpic.jpg').convert('L'))
#imshow()根据数组绘制图像
imshow(im)
#x表示点的横坐标,y表示点的纵坐标
x=[10,10,40,40]
y=[20,50,20,50]
plot(x,y,'g+')
plot(x[:2],y[:2]) #用线连接点(10,20)和(10,50)
title('Plot:testpic.jpg')
#不显示坐标轴

axis('off')          

原图:

均衡化图像:

____________________________________________________
#figure()用于新建一个图像
figure()
#gray()不使用颜色信息
gray()
#在原点的左上角显示轮廓图像
contour(im,origin='image')         ###
axis('equal')

axis('off')

轮廓图:

——————————————————————————————
figure()
#hist()用于绘制灰度图像的直方图,第一个参数只能是一维数组,第二个参数是小区间数目
#flatten()用于将任意数组按“行优先准则”转换成一维数组
hist(im.flatten(),8)         
#show()显示绘制的图像

show()

直方图:

——————————————————————————————
#ginput()用于交互式标注,即用户指定输入
imginput=array(Image.open('testpic.jpg'))
imshow(imginput)
print('Click 4 points')
#点击的坐标自动保存在x列表中
x=ginput(4)

print('you clicked:',x)







原创粉丝点击