Writing JPG with alpha channel

asked 2016-06-09 11:04:52 -0600

fijoy gravatar image

updated 2020-10-24 02:28:58 -0600

Hi all,

It seems that OpenCV cannot write JPEG images with alpha channel. For example, the code

Mat readMat = imread("water.png", IMREAD_UNCHANGED);
imwrite(string("water.jpg"), readMat);

using water.png, a 4-channel image downloaded from here with white background, produces a jpg image with 3 channels and black background. Is this a bug in OpenCV, or expected behavior?

Thanks.

edit retag flag offensive close merge delete

Comments

jpg does not have any alpha channel, try "png" instead.

(and then, just saying, alpha has no relevance in computer-vision.)

berak gravatar imageberak ( 2016-06-09 11:09:42 -0600 )edit

I also tried to save in JPEG 2000 format using imwrite(string("water.jp2"), readMat), and got a blank file as result. JPEG 2000 is supposed to support alpha channel, correct?

fijoy gravatar imagefijoy ( 2016-06-09 11:16:05 -0600 )edit

idk.

again alpha is of no relevancy at all to opencv, and you're better off, avoiding images, that have it in the src file (if you want to do like dtp-image-processing, you picked the wrong lib)

berak gravatar imageberak ( 2016-06-09 11:19:59 -0600 )edit