Unexpected results while copying transparent image over another image. [closed]

asked 2017-01-23 04:43:59 -0600

kartikeygupta9097 gravatar image

updated 2017-01-23 05:43:57 -0600

I have a transparent PNG image (shown below)... image description

and another image (shown below) image description

I want to copy the resize the first image and place it over the second image, and I tried doing so using the resize() and copyTo() functions. But the result was not what I expected or wanted...

image description

How do I get rid of that green color in the background?

EDIT - So, I did further research and found that this is probably because I am using a three channel image and I need to use a four channel image. So how do I convert a 3-channel image to a 4-channel image?

edit retag flag offensive reopen merge delete

Closed for the following reason question is off-topic or not relevant by berak
close date 2017-01-23 05:45:09.297000


opencv might be the wrong library for this, entirely.

almost any operations ignore or discard alpha here, as it is of no relevance in computer-vision.

(you'd have to do your own, manual blending, also imshow will just discard alpha.

berak gravatar imageberak ( 2017-01-23 05:43:29 -0600 )edit
sturkmen gravatar imagesturkmen ( 2017-01-23 06:11:47 -0600 )edit

TL;DR - I created my own blending procedure, but it's pretty basic...

Don't have enough karma points to reopen the question, but I figured out the solution. I imported the overlay image as a 4-channel image, and converted the underlay image into a 4-channel image. Then I set the origin of the overlay image on the underlay image, and ran a for loop(i=0->overlay.rows) within a for loop(j=0->overlay.cols). If the alpha parameter for the overlay[i][j] was 0, I set the underlay[i+origin.y][j+origin.x]'s RGBA to underlay[i][j]'s RGBA....

kartikeygupta9097 gravatar imagekartikeygupta9097 ( 2017-02-19 12:54:20 -0600 )edit