Invert colors when plotting a PNG file using matplotlib

后端 未结 4 1938
-上瘾入骨i
-上瘾入骨i 2021-01-12 19:33

I\'m trying to display a PNG file using matplotlib and of course, python. For this test, I\'ve generated the following image:

4条回答
  •  走了就别回头了
    2021-01-12 20:27

    As others have pointed out, the problem is that numpy arrays are in BGR format, but matplotlib expects the arrays to be ordered in a different way.

    You are looking for scipy.misc.toimage:

    import scipy.misc
    rgb = scipy.misc.toimage(cube)
    

    Alternatively, you can use scipy.misc.imshow().

提交回复
热议问题