马春杰杰 Exit Reader Mode

如何对numpy数组可视化?如何将numpy数组保存为图片?

推荐使用matplotlib

import matplotlib
 
matplotlib.image.imsave('xxx.png', array)

这是对应解释:

Arguments:
  *fname*:
    A string containing a path to a filename, or a Python file-like object.
    If *format* is *None* and *fname* is a string, the output
    format is deduced from the extension of the filename.
  *arr*:
    An MxN (luminance), MxNx3 (RGB) or MxNx4 (RGBA) array.

保存的图片类似彩图。

当然,OpenCV也行:

import cv2
import numpy as np
 
cv2.imwrite("xxx.png", array)

 

本文最后更新于2021年12月31日,已超过 1 年没有更新,如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢!