ali*_*i_m 13
.npy是numpy数组的文件扩展名 - 您可以使用numpy.load以下命令读取它们:
import numpy as np
img_array = np.load('filename.npy')
Run Code Online (Sandbox Code Playgroud)
查看它们的最简单方法之一是使用matplotlib的imshow函数:
from matplotlib import pyplot as plt
plt.imshow(img_array, cmap='gray')
plt.show()
Run Code Online (Sandbox Code Playgroud)
您也可以使用PIL或枕头:
from PIL import Image
im = Image.fromarray(img_array)
# this might fail if `img_array` contains a data type that is not supported by PIL,
# in which case you could try casting it to a different dtype e.g.:
# im = Image.fromarray(img_array.astype(np.uint8))
im.show()
Run Code Online (Sandbox Code Playgroud)
这些函数不是Python标准库的一部分,因此如果您还没有安装matplotlib和/或PIL/pillow,则可能需要安装它们.我还假设文件是2D [rows, cols](黑色和白色)或3D [rows, cols, rgb(a)](颜色)像素值数组.如果情况并非如此,那么您将不得不告诉我们更多关于数组格式的信息,例如什么img_array.shape和img_array.dtype是什么.
| 归档时间: |
|
| 查看次数: |
15086 次 |
| 最近记录: |