OpenCV---如何将彩色图像分通道输出(4)

附代码如下:

import cv2 as cv
import numpy as np
def ch():
    src = cv.imread("D:/matplotlib/0.jpg")
    h,w,ch = np.shape(src)
    bgr = cv.split(src)
    cv.imshow("blue",bgr[0])
    cv.imshow("green",bgr[1])
    cv.imshow("red",bgr[2])
    print(h,w,ch)
    cv.waitKey(0)
    cv.destroyAllWindows()
ch()

运行效果:

代码解释:

import cv2 as cv
import numpy as np
def ch():
    src = cv.imread("D:/matplotlib/0.jpg")
    h,w,ch = np.shape(src)
    bgr = cv.split(src)
    #将彩色图像拆分成单个通道
    cv.imshow("blue",bgr[0])
    cv.imshow("green",bgr[1])
    cv.imshow("red",bgr[2])
    #分别显示每个通道的图像
    print(h,w,ch)
    cv.waitKey(0)
    cv.destroyAllWindows()
ch()

猜你喜欢

转载自blog.csdn.net/sy20173081277/article/details/84767190
今日推荐