I'm attempting to superimpose two images together to mimic the result of an image that was superimposed using MatLab. Unfortunately I'm not able to use MatLab for this project and my method of using blending doesn't give the desired result.

Any ideas on how to accomplish this superimposing of the images using just Python?
Here is the section of code that I've attempted to use a blending method. However, it results in a glowing effect:
# Blend method from
# http://www.deepskycolors.com/archive/2010/04/21/formulas-for-Photoshop-blending-modes.html
target = img_1 / 255.0
blend = img_2 / 255.0
output_img = (target > 0.5) * (1 - (1-2*(target-0.5)) * (1-blend)) + (target <= 0.5) * ((2*target) * blend)
output_img = output_img*255.0
Here are the two images I am starting with:

You can do this with Pillow:
from PIL import Image
im1 = Image.open("background.jpg")
im2 = Image.open("bird.jpg")
newimg = Image.blend(im1, im2, alpha=0.5)
newimg.save("blended.jpg")
I get this result:

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With