代码:
import numpy as np
import imageio
rawfile = np.fromfile('./_DSC7472.ARW', dtype=np.float32) # 以float32读图片
print(rawfile.shape)
rawfile.shape = (896, 13709)
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()
输出:
rawfile.shape的大小为:12283264
注意:
reshape的乘积必须要等于原始的图片大小,896*13709=12283264.
因数分解可以参照:因数分解链接。
问题:
虽然我现在的图片可以转换成jpg了,但是reshape太畸形,导致我的原始图片直接就没办法使用。
解决方法:
电脑自带的zip软件进行转换:
安转zip包——>将图片用zip看图打开——>图片另存为jpg即可。