例一:
一、要求
读入0.raw的文件,转化为0.jpg文件。
二、代码
import numpy as np
import imageio
rawfile = np.fromfile('0.raw', dtype=np.float32) # 以float32读图片
print(rawfile.shape)
rawfile.shape = (480, 640)
print(rawfile.shape)
b=rawfile.astype(np.uint8)#变量类型转换,float32转化为int8
print(b.dtype)
imageio.imwrite("0.jpg", b)
import matplotlib.pyplot as pyplot
pyplot.imshow(rawfile)
pyplot.show()
三、运行结果
这里有个问题:将黑白两通道的图像放到了pyplot三通道中,导致了奇怪的颜色。
例二:
一、要求
从jpg图像生成raw图像,对该raw图像进行显示