一文读懂图像中的通道
目标检测与深度学习
共 2273字,需浏览 5分钟
·
2021-05-08 13:08
![](https://filescdn.proginn.com/e96dc83ae0f01cc863107cd21c077d15/340d9d9f5676f3e8411b500a069f3746.webp)
灰度图像
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)
![](https://filescdn.proginn.com/6dd2152414a3bb7fda566b4839074b54/82b0389c632ffb6f894ed3ed5e7eba94.webp)
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)
![](https://filescdn.proginn.com/df82679b94e8aa12ebd1f0f24829b2f3/f8b23b2cfa59702e11bcd1522761cbc1.webp)
分别显示每个通道
![](https://filescdn.proginn.com/8e30d184fb5443a03c1c3dab9afa531e/855d07c3e6eae1c965efb4c05af7a312.webp)
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()
![](https://filescdn.proginn.com/6124c3e6c9deef2d1b0b8d5e73d17074/ab890ce827d142571ba97c566280d6c7.webp)
![](https://filescdn.proginn.com/9f476a8fe5a094c036fb12bd156a1273/dfda97b5d8d6e9246382cae2cf38dbb9.webp)
![](https://filescdn.proginn.com/3f12343e364cde4ce9e5c390f444b080/1fab2b77c6194755102b3015aee5da75.webp)
双一流高校研究生团队创建 ↓
专注于计算机视觉原创并分享相关知识 ☞
整理不易,点赞三连!
评论