python+opencv实操-图像基本操作

直接上code吧,暂记于此。

from PIL import Image                                #导入图像库中的Image
from pylab import *


pil_im_rgb = Image.open('e:\PC.jpg')
pil_im_rgb.show()

#(1)转化为灰度图像
pil_im_gray = Image.open('e:\PC.jpg').convert('L')   
pil_im_gray.show()

#(2)转化为q其他格式的图片
pil_im_rgb.save('e:\PC.PNG');
pil_im_rgb.save('e:\PC.BMP');

#(3)图像缩放
pil_im_small = pil_im_gray.resize((240,240))
pil_im_small.show()

#(4)图像旋转,默认是逆时针旋转,如果为负数则变为顺时针旋转
pil_im_rotate = pil_im_small.rotate(45)
pil_im_rotate.show()
pil_im_rotate = pil_im_small.rotate(-45)
pil_im_rotate.show()

#(5)图像的宽高,指定位置的像素值
print pil_im_rgb.width
print pil_im_rgb.height
print pil_im_rgb.getpixel((1,1))


#查看帮助函数
help(Image)


兼容matlab的一些用法,其实是有一个叫做numpy的库。实现了类似matlab的功能。

from PIL import Image                  #导入图像库中的Image
from pylab import *                    #pylab 中包含matplotlib,为了兼容matlab的一些功能


# read image to array
im = array(Image.open('e:\PC.jpg').convert('L'))
# plot the image
imshow(im)
# some points
x = [100,100,400,400]
y = [200,500,200,500]
# plot the points with red star-markers
plot(x,y,'r*')
# line plot connecting the first two points
plot(x[:2],y[:2])
# add title and show the plot
title('testing')
show()


contour(im, origin='image')
axis('equal')
axis('off')



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值