Opencv - Image Overlay Without cvAddWeighted

There are many tutorials showing how to mix two images in opencv:

But they are all based on this equation:

opencv blending http://opencv.itseez.com/_images/math/afeb868ed1632ace1fe886b5bfbb6fd933b742b8.png

which means that I will combine the two images by averaging them, and therefore I will lose intensity in both images.

For example, let alpha = 0.5, f0 (x) = 255, and f1 (x) = 0. After applying this equation, the image of the result is g (x) = 127. This is not what I need. The first image should remain unchanged. And transparency should be applied in the second.

My problem:

the first image f0 (x) should not be changed, and alpha should be applied to the second image f1 (x) when it overlays the first image f0 (x).

I can’t figure out how to do this. Any help?

0
source share
1 answer

Unfortunately, alpha channels are not supported by OpenCV. From the imread documentation:
Note that in the current implementation, the alpha channel, if any, is removed from the output image. For example, a 4-channel RGBA image is loaded as RGB if flags > 0 .

See this SO post for a possible work using imagemagick.

Hope this will be helpful!

0
source

All Articles