0

there are plenty of tutorials showing how to blend two images in opencv:

But all of them are based on this equation:

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

which means that I will be combining two images by averaging them and consequently I'll be loosing intensity on both images.

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

My problem is:

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

I cannot figure out how to do this. Any help?

Utkarsh Sinha
  • 3,295
  • 4
  • 30
  • 46
Sam Felix
  • 1,329
  • 1
  • 10
  • 23
  • Everyone who landed on this post should probably read [the answer over there](https://stackoverflow.com/a/49180468/176769). – karlphillip Mar 08 '18 at 19:16

1 Answers1

0

Unfortunately, alpha channels are not supported by OpenCV. From the imread documentation:
Note that in the current implementation the alpha channel, if any, is stripped 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 around using imagemagick.

Hope that is helpful!

Community
  • 1
  • 1
mevatron
  • 13,911
  • 4
  • 55
  • 72
  • thank you @mevatron for pointing me towards ImageMagick. here is the answer: composite -dissolve 50% meme1.png meme2.png result.png. It is also possible to code in c++ using Magick++. – Sam Felix Nov 26 '11 at 22:45