针对图像的一些简单操作

python有很强大的图像处理的库目前用额有两个PIL(python Imaging Library)和Pillow库,后者是前者的扩展,使用的时候要注意先引用from PIL import Image这样使用。由于PIL库已经停止更新,所直接来学习pillow库处理图像。这里我们还会用到一个专业的绘图库matplotlib用来绘制显示图像,他的figure特性可以用来显示标题,subplot在一个figure中显示多张图片也是可以的。
代码:

coding:utf-8

from PIL import Image
import matplotlib.pyplot as plt
im = Image.open(r’C:\Users\Administrator\Desktop\image\image2\1.jpg’,’r’)

格式,尺寸,色彩mode

im.format,im.size,im.mode

标题

plt.figure(“2”)

色彩mode

plt.imshow(im.convert(‘P’))

转换角度

plt.imshow(im.rotate(270))
plt.show()
plt.axis(‘off’)

保存图片

im.save(‘.girls.jpg’)

convert() 是图像实例对象的一个方法,接受一个 mode 参数,用以指定一种色彩模式,mode 的取值可以是如下几种:
· 1 (1-bit pixels, black and white, stored with one pixel per byte)
· L (8-bit pixels, black and white)
· P (8-bit pixels, mapped to any other mode using a colour palette)
· RGB (3×8-bit pixels, true colour)
· RGBA (4×8-bit pixels, true colour with transparency mask)
· CMYK (4×8-bit pixels, colour separation)
· YCbCr (3×8-bit pixels, colour video format)
· I (32-bit signed integer pixels)
· F (32-bit floating point pixels)
LA (L with alpha),
RGBX (true colour with padding)
RGBa (true colour with premultiplied alpha)

附上两张图片来看一下。。

《针对图像的一些简单操作》 _)SN%[TN_S}MRE]$Z“M@ZM.png

![R5G`8R8$_]R}IPR4P2LEQKS.png](http://upload-images.jianshu.io/upload_images/1516470-deac7f62832db381.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

附加的学习了下别人的那个制作二维码太有趣了@隋胖胖,可以使用一个qrcode库来实现非常简单,好有趣。

就是引入需要的库,设置需要转换的内容并转换,生成,保存这几个步骤

《针对图像的一些简单操作》 O1ZMOOXO{U11)MRY3I2)YA5.png

    原文作者:sunlin1234
    原文地址: https://www.jianshu.com/p/00af42c234c3
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞