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))