Adding an alpha channel to a Monochrome Image using Open CV Python

只愿长相守 提交于 2019-11-30 15:19:21

You cannot create a 2-channel "luminance-alpha" image, however you can convert the 1-channel grayscale image to BGRA using only gray values by duplicating the grayscale channel and adding the alpha channel to that. Let l be the grayscale image:

img_3gray = cv2.merge((l,l,l,a))

Nor can you apply an alpha channel to just one channel of an image, but you can take a single channel of the image (say, blue) and turn it into a grayscale image as we did before:

img_3blue = cv2.merge((b,b,b,a))

or you can display only the blue channel with alpha:

img_bzz = cv2.merge((b,z,z,a))

where z is all zeroes.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!