zhiqingstudy

Be a young person with knowledge and content

For an image, we can do some processing on its channels. The normal image includes three channels of BGR. How can we separate and merge the channels together? The first two apis you need to know to realize channel separation and merging.
  1. Split (mat): split the picture channel. The input is a mat type picture. After the split, multiple channels are output.
  2. Merge ((ch1, ch2,...)): Combines multiple channels together.
import cv2
import numpy as np

# 创建一个黑色图片
img=np.zeros((480,640,3),np.uint8)
# 通道分割
b,r,g=cv2.split(img)
# 修改部分通道
g[10:100,10:100]=255
r[10:100,10:100]=255
# 通道合并
img2=cv2.merge((r,g,b))

cv2.imshow('img',img)
cv2.imshow('b',b)
cv2.imshow('g',g)
cv2.imshow('r',r)
cv2.imshow('rg',img2)
cv2.waitKey(0)
comment
head sculpture
Code:
Related

Why you shouldn't stay at a job for more than 2 years?

3 harsh facts long-distance relationships

how to keep your girlfriend interested in a long-distance relationship




Unless otherwise specified, all content on this website is original. If the reprinted content infringes on your rights, please contact the administrator to delete it
Contact Email:2380712278@qq.com

Filing number:皖ICP备19012824号