繁体   English   中英

使用 MatplotLib 或 Pillow 转换图像

[英]Conversion of Image using MatplotLib or Pillow

我有一张尺寸为 (1000,1000,4) 的图像,我想将其转换为 (1000,1000,3)。 如何使用 matplotlib 或 python 中的枕头模块执行此操作?

通常,您会将阵列保存为 numpy 阵列,将其展平,然后对其进行整形。 但是,您不能将 (1000,1000,4) 转换为 (1000,1000,3)。 A (1000,1000,4) 有 1000 x 1000 x 4 个元素,无法转换为存储 1000 x 1000 x 3 个元素的数组。 你将不得不摆脱一些元素。

import numpy as np
arr = np.array(your_array) 
arr.flatten().reshape((x dim,y dim ,z dim))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM