如上图,我电脑上有个npy文件。
我要把它读取出来,代码如下:
import numpy as np
import cv2
import matplotlib.pyplot as plt
file_dir = "./Fold_2/images/fold2/images.npy" # npy文件路径
dest_dir = "./Fold_2/images/fold2/images_png/" # 文件存储的路径
image = np.load(file_dir)
for i in range(0,image.shape[0]):
plt.imshow(image[i,:,:])
cv2.imwrite(dest_dir+str(i)+".png",image[i,:,:])
# plt.show()
print("successful!")
结果: