一文读懂图像中的通道
灰度图像
import cv2 as cv
image = cv.imread("D://medium_blogs//architecture.jpg")
gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
print(gray)
print("")
print(gray.shape)
RGB图像
import cv2 as cv
image = cv.imread("D://medium_blogs//architecture.jpg")
RGB = cv.cvtColor(image, cv.COLOR_BGR2RGB)
print(RGB)
print("")
print(RGB.shape)
分别显示每个通道
import cv2 as cv
import numpy as np
image = cv.imread("D://medium_blogs//colours.jpg")
image = cv.cvtColor(image, cv.COLOR_BGR2RGB)
(R,G,B) = cv.split(image)
cv.namedWindow("Blue", cv.WINDOW_NORMAL)
cv.namedWindow("Green", cv.WINDOW_NORMAL)
cv.namedWindow("Red", cv.WINDOW_NORMAL)
cv.imshow("Blue",B)
cv.imshow("Green", G)
cv.imshow("Red", R)
cv.imwrite("D://medium_blogs//channel_red.jpg", R)
cv.imwrite("D://medium_blogs//channel_green.jpg", G)
cv.imwrite("D://medium_blogs//channel_blue.jpg", B)
if cv.waitKey(0):
cv.destroyAllWindows()
双一流高校研究生团队创建 ↓
专注于计算机视觉原创并分享相关知识 ☞
整理不易,点赞三连!
评论