0

The mask edge is soft, like this:

enter image description here

and Result with this mask in photoshop is:

enter image description here

After cv2.bitwise_and ,So bad the result is!

enter image description here

How can I handel this like photoshop,or any other method in python-opencv can do this?

Thanks!

叶同学
  • 801
  • 1
  • 9
  • 21

1 Answers1

1

If you want the transparent effect like in photoshop, you need to use an alpha channel. See this question.

If you want to composite the image with another background, you can use the alpha matting formula I = aF+(1-a)B, where a the alpha, F the foreground and B the background. Like this:

ex_alpha = np.repeat(alpha[:, :, np.newaxis], 3, axis=2)
output = (foreground*ex_alpha) + (1-ex_alpha)*background

The repeat exists because foreground/background are 3-channels while alpha is 1-channel.

hkchengrex
  • 4,361
  • 23
  • 33