Python PIL(Python Image Library)使用体会

python中的函数实在太多了,要想全面的使用所有的库函数还是要长久的积累,今天看代码时,看见了PIL类,在此对PIL做一个简单的总结。
参考1 参考2

#读取图片
im=Image.open('/home/Picture/test.jpg')
#保存图片
im.save("save.jpg")  
#逆时针旋转45度 
out = img.rotate(45) 
# 类型转换
xx = yy.convert('RGB') #转为RGB
xx = yy.convert('L') #转为灰度
#将uint8类型的数据转换为Image类下的文件
arr = (eye(200)*255).astype('uint8') # sample array
im = Image.fromarray(arr)

# 转换list->array->unit8 array->Image
img=Image.fromarray(numpy.array(data).reshape((48,48)).astype('uint8'))

#转换 Image->uint8 array
data=numpy.array(img_r)


# 灰度图转RGB
im = Image.fromarray(arr).convert('RGB')
#使用python可以通过使用convert(‘L')来获得灰度图

#对原始图像resize
im.resize((224,224))
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值