Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

you can't (at least not so easily.)

when working with computer-vision, you should avoid images with alpha in it, those only cause trouble.

what you could try is:

 # read it in "as is":
im = cv2.imread("iconx.png", -1)

# extract the alpha channel:
a:= im[:,:,3]

#use that as a mask for bitwise compositing:
im2 = cv2.bitwise_and(im,im,mask=a)

#convert *that* to grayscale
im2 = cv2.cvtColor(im2,cv2.COLOR_BGRA2GRAY)

image description