我正在关注本教程:https://pyts.readthedocs.io/en/latest/auto_examples/plot_gaf.html为了生成GADF和GASF矩阵。
一切正常。
我只需要将 X_gasf[0]
中包含的结果保存为 png,但我不知道该怎么做。
我已经尝试过这个:
fig = plt.imshow(X_gadf[0], cmap='rainbow', aspect='equal')
fig.axes.get_xaxis().set_visible(False)
fig.axes.get_yaxis().set_visible(False)
plt.axis('off')
plt.savefig(GADF_path + filename, pad_inches=0, bbox_inches='tight')
这段代码有效,但仍然在图像周围给出了白色边框(对我来说不要有任何白色边框非常重要)。
我也尝试过这个:
# Test 1
matplotlib.image.imsave(filename, X_gadf[0])
# Test 2
im = Image.fromarray(X_gadf[0], mode='HSV')
im.save(GADF_path + filename)
# Test 3
cv2.imread(X_gadf[0])
imsave(filename, X_gadf[0])
但是这些解决方案都不起作用。似乎 X_gadf[0]
是一种我无法管理的奇怪类型的图像。
有什么想法吗?
最佳答案
你尝试过这个吗?
matplotlib.image.imsave(filename, X_gasf[0], cmap='rainbow')
查看文档,您似乎忘记了cmap='rainbow'
关于python - 将彩虹矩阵转换为 RBG 并另存为 PNG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54135151/