原图:
BGR转RGB



源代码:
#coding=utf-8

#OpenCV读进来的图像,通道顺序为BGR,  而matplotlib的顺序为RGB,因此需要转换
import cv2
import numpy as np
from matplotlib import pyplot as plt


img = cv2.imread('./test1.jpg')
B, G, R = cv2.split(img)

#BGRRGB,方法1
img_rgb1 = cv2.merge([R, G, B])

#BGRRGB,方法2
img_rgb2 = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

#BGRRGB,方法3
img_rgb3 = img[:,:,::-1]


plt.figure('BGR_RGB')

#显示opencv读进来的img, 通道顺序BGR
plt.subplot(3,3,1), plt.imshow(img)
#显示B通道
plt.subplot(3,3,4), plt.imshow(B)
#显示B通道
plt.subplot(3,3,5), plt.imshow(G)
#显示B通道
plt.subplot(3,3,6), plt.imshow(R)
#显示将BGR转为RGB的图像,3种方法
plt.subplot(3,3,7), plt.imshow(img_rgb1)
plt.subplot(3,3,8), plt.imshow(img_rgb2)
plt.subplot(3,3,9), plt.imshow(img_rgb3)

plt.show()


运行后图BGR转RGB

相关文章:

  • 2021-06-07
  • 2021-07-26
  • 2021-08-08
  • 2022-12-23
  • 2021-04-30
  • 2022-12-23
  • 2021-06-23
  • 2021-10-28
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-25
  • 2021-08-27
  • 2021-04-05
  • 2022-12-23
相关资源
相似解决方案