I am working on color images (RGB) and color images with alpha channel (RGBA). Reading the alpha channel from an RGBA image is pretty simple, and I can even split 4 channels of the image. Is there any way I can add an alpha channel to a monochrome or grayscale image? In addition, can a separate channel be separately added to channels R, G, B separately?
The code that I use to read a transparent image and split channels looks like this:
import cv2
img = cv2.imread(image1_path,-1)
b = img[:,:,0]
g = img[:,:,1]
r = img[:,:,2]
a = img[:,:,3]
img_merge = cv2.merge((b,g,r,a))
cv2.imshow("img_merge",img_merge)
cv2.imshow("r channel",r)
cv2.imshow("g channel",g)
cv2.imshow("b channel",b)
cv2.imshow("a channel",a)
cv2.waitKey(0)
cv2.destroyAllWindows()
The image I'm using is

source
share