4. 将 numpy 数组转换为 PIL 图片
这里采用 matplotlib.image 读入图片数组,注意这里读入的数组是 float32 型的,范围是 0-1,而 PIL.Image 数据是 uinit8 型的,范围是0-255,所以要进行转换:
|
1
2
3
4
5
|
import matplotlib.image as mpimgfrom PIL import Imagelena = mpimg.imread('lena.png') # 这里读入的数据是 float32 型的,范围是0-1im = Image.fromarray(np.uinit8(lena*255))im.show() |
5. RGB 转换为灰度图
|
1
2
3
4
5
|
from PIL import ImageI = Image.open('lena.png')I.show()L = I.convert('L')L.show() |
以上就是本文的全部内容,希望对大家的学习有所帮助













