0

I have a picture like this and i want to remove the background by adding a layer on top the image just like how photoshop layout works.

Original Picture enter image description here

Mask/Layer enter image description here

Final desired output enter image description here

I am trying to do this iwth opencv's addweighed function but i am not able to get the desired output

im_overlay = cv2.imread('%s/%s.png'%(_src,camera_name.split(".")[0]))
img = cv2.addWeighted(im, 1, im_overlay, 0.0, 0)
showImage(img)
shahidammer
  • 752
  • 5
  • 18
  • Possible duplicate of [This](https://stackoverflow.com/questions/40895785/using-opencv-to-overlay-transparent-image-onto-another-image) or [This](https://stackoverflow.com/questions/14063070/overlay-a-smaller-image-on-a-larger-image-python-opencv) – Arkistarvh Kltzuonstev Mar 04 '19 at 11:13
  • Already tried that, as mentioned in the problem the code did not work for me – shahidammer Mar 04 '19 at 11:14

1 Answers1

1

The format of the mask is strange for OpenCv to read on my system (using opencv 3.4.2). I was able to read it with cv2.IMREAD_UNCHANGED but it show me that your mask has 4 channels (I was expecting only one channel). The code below produce opposite or what you would expect:

 img = cv2.imread(r"C:\Users\...\Desktop\\W1kle.jpg")
 mask = cv2.imread(r"C:\Users\...\Desktop\LZdyB.png",cv2.IMREAD_UNCHANGED) 
 mask = mask[:,:,3]
 res = cv2.bitwise_and(img,img,mask=mask)
 cv2.imshow("image",res)
 cv2.waitKey(0)

Hope this helps you :)

wdudzik
  • 1,084
  • 11
  • 20
  • You are right it is opposite to what i was looking for but to make it work on my case, i reversed the mask. Works smoothly. Thanks – shahidammer Mar 04 '19 at 12:16