Read a gray scale or monochrome image with alpha channel

asked 2016-09-15 00:12:27 -0500

kampta gravatar image

updated 2016-09-15 00:59:10 -0500

berak gravatar image

Repeating a question from stackoverflow.

How can I read a gray scale image in OpenCV with alpha channel? For example, if I try to read the following image, all I get is 2d array of all zeros.

C:\fakepath\1.png

image = cv2.imread('1.png', cv2.IMREAD_UNCHANGED)
image.shape

(480, 960)
edit retag flag offensive close merge delete

Comments

believe it or not, opencv is a computer-vision library, where alpha channels have no relevance at all.

berak gravatar imageberak ( 2016-09-15 01:10:54 -0500 )edit

which opencv version do you use ? you might be missing this

berak gravatar imageberak ( 2016-09-15 01:56:54 -0500 )edit

Saving/loading images with alpha channels come handy while working on problems related to foreground/background extraction, object segmentation

kampta gravatar imagekampta ( 2016-09-15 02:06:46 -0500 )edit

I am using opencv 3.1 with python 3.5, let me try out the development version

kampta gravatar imagekampta ( 2016-09-15 02:07:39 -0500 )edit

just don''t expect too much. even, if you can load it, imshow won't be able to blit it correctly.

berak gravatar imageberak ( 2016-09-15 03:15:50 -0500 )edit