1. 程式人生 > >OpenCV---如何將彩色影象分通道輸出(4)

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()