I'm trying to display a PNG file using matplotlib and of course, python. For this test, I've generated the following image:
现在,我加载图像并将其转换为多维 numpy 矩阵:
import numpy as np
import cv2
from matplotlib import pyplot as plt
cube = cv2.imread('Graphics/Display.png')
plt.imshow(cube)
plt.ion()
When I try to plot that image in matplotlib, the colors are inverted:
如果矩阵没有任何修改,为什么图中的颜色是错误的?
提前致谢。
看来你可能有RGB
切换为BGR
。请注意,绿色被保留,但所有蓝色都变成红色。如果cube
形状为 (M,N,3),尝试交换cube[:,:,0]
with cube[:,:,2]
。你可以这样做numpy
像这样:
rgb = numpy.fliplr(cube.reshape(-1,3)).reshape(cube.shape)
来自OpenCV文档:
注意:对于彩色图像,解码后的图像将具有
频道按 B G R 顺序存储。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)