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

后端 未结 1 1211
生来不讨喜
生来不讨喜 2021-01-03 04:01

I have been working on colour images(RGB) and color images with an alpha channel(RGBA) . Reading an alpha channel from an RGBA image is pretty easy and I can even split the

相关标签:
1条回答
  • 2021-01-03 04:49

    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.

    0 讨论(0)
提交回复
热议问题