以下内容将png读入数组:
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
img=mpimg.imread('example.png')
结果是数组img
,例如1024x1024元组数组(参见http://matplotlib.org/1.3.1/users/image_tutorial.html):
如何强制执行,我的结果是一个n x n数组(元组)而不是1024 x 1024数组(n<;1024)?我需要明确定义该数组的维度(例如,设置400x400)。你知道吗
提前谢谢
我建议安装
pillow
(最好使用Anaconda)。它使图像处理变得简单-比将图像作为原始图像处理更容易。你知道吗一旦安装了
pillow
,这个答案应该会有帮助:How do I resize an image using PIL and maintain its aspect ratio?如果您真的想把它作为一个数组,那么可以使用^{} 。你知道吗
编辑添加实际有效的内容,以防其他人错过:
相关问题 更多 >
编程相关推荐