可变大小的numpy数组

问题描述 投票:3回答:1

我正在使用skimage.io.imread加载图像并将图像保存为numpy数组。以下是感染:

原图:(256x512x3)

enter image description here

以下是我执行的代码:

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

任何人都可以解释为什么图像的大小如此巨大的差异?

编辑:i1i2final_image的dtype是np.float64

python arrays image numpy scikit-image
1个回答
2
投票

numpy.empty默认为np.float_在你的系统上,但是,你的图像应该被读作np.uint8,所以提供相应的dtypeempty

final_image = np.empty([1, 2, 256, 256, 3], dtype=np.uint8)
© www.soinside.com 2019 - 2024. All rights reserved.