OpenCV 2.4 Jpeg for PNG with alpha

I have a JPEG and a mask. I want to create a PNG with three JPEG channels, and the alpha channel should be a mask. How can I achieve this with OpenCV?

Hi

+7
source share
2 answers

Thanks for your answer, I found the second solution:

cv::Mat transparent( height, width, CV_8UC4); cv::Mat srcImg[] = {JPEG_img, alpha_Mask}; int from_to[] = { 0,0, 1,1, 2,2, 3,3 }; cv::mixChannels( srcImg, 2, &transparent, 1, from_to, 4 ); 

This works fine, not sure which solution is better.

+6
source
 std::vector<cv::Mat> channels; cv::split(jpgImage, channels); channels.push_back(mask); cv::Mat bgraImage; cv::merge(channels, bgrAImage); 

Documentation for the split and merge function

+8
source

All Articles