我正在使用skimage.io.imread
加载图像并将图像保存为numpy数组。以下是感染:
原图:(256x512x3)
以下是我执行的代码:
img = io.imread(img_file) # 48.1 kB
i1, i2 = img[:, :256], img[:, 256:]
np.save('i1', i1) # 196.7 kB
np.save('i2', i2) # 196.7 kB
final_image = np.empty([1, 2, 256, 256, 3])
final_image[0, 0], final_image[0, 1] = i1, i2
np.save('final', final_image) # 3.1 MB
任何人都可以解释为什么图像的大小如此巨大的差异?
编辑:i1
,i2
,final_image
的dtype是np.float64
numpy.empty
默认为np.float_
在你的系统上,但是,你的图像应该被读作np.uint8
,所以提供相应的dtype
到empty
:
final_image = np.empty([1, 2, 256, 256, 3], dtype=np.uint8)