【发布时间】:2021-08-15 16:15:39
【问题描述】:
尝试使用下面的代码读取 .npy 文件的图像,但出现以下错误
输入This is the link to download the images where the file size is >10GB
import numpy as np
from matplotlib import pyplot as plt
import matplotlib
import glob
for filename in glob.glob("*.*"):
if '.npy' in filename:
img_array = np.load(filename, allow_pickle=True)
plt.imshow(img_array, cmap="gray")
img_name = filename+".png"
matplotlib.image.imsave(img_name, img_array)
print(filename)
输出
TypeError: Invalid shape (601, 660, 14) for image data
【问题讨论】:
-
文件是如何保存的?正如您从错误中看到的那样,图像是不规则的形状,并且可能被错误地保存/加载
-
图像是一个.npy文件,我正在将它转换为一个.png文件,当我们看到图像的形状时,图像的尺寸是14,当我试图读取.npy 文件,它由数字数组组成
-
问题与
machine-learning或artificial-intelligence无关,请不要发送无关标签(已删除)。 -
来自
imshow文档:支持的数组形状为 (M, N) 或 (M, N, 3) 或 (M, N, 4)。但是您的img_array是 (M,N,14)。也许您的img_array包含 14 个不同的 601x660 图像的数据? -
根据数据集,它不是一个单一的图像,它的图像对,我们还有一个 csv 文件,这些信息有助于解决这个问题吗??
标签: python python-3.x opencv matplotlib image-processing