python3 raw 數據轉換為jpg
我們大家都知道,sensor 直接出來的裸數據為raw 數據,沒有經過編解碼,壓縮。
我們需要將raw數據轉換為其他格式比如jpg,png,bmp 人眼才能看到。好了,廢話不多說,直接上代碼。
import numpy as np
import imageio
rawfile = np.fromfile('C:/Users/awssome/Desktop/3.raw', dtype='uint16') # 以int16讀圖片
print(rawfile.shape)
rawfile.shape = (1520, 2688)
print(rawfile.shape)
b=rawfile.astype('uint16')#變量類型轉換
print(b.dtype)
imageio.imwrite("C:/Users/awsome/Desktop/3.jpg", b)
import matplotlib.pyplot as pyplot
pyplot.imshow(rawfile)
pyplot.show()