【发布时间】:2021-01-17 13:53:07
【问题描述】:
在将 PNG 文件转换为 numpy 数组时,我注意到转换有时会导致不同的数组形状。而the first image 具有三维阵列形状(与大多数图像一样)the second one 具有二维。图像均为屏幕截图,未经更改。不幸的是,数组形状对于我的预期用途确实很重要。
我使用下面的代码进行图像转换。
import numpy as np
import PIL.Image
img_path = '' # Put the image path here
img_pil = PIL.Image.open(img_path)
img_array = np.asarray(img_pil)
print(img_array.shape)
我的问题是是否有办法对齐图像的形状。
【问题讨论】:
标签: python arrays numpy image-processing python-imaging-library