How to overlay two images?

I want to overlay two images, the one of hair and the one of skin. When I try this code:
blended = Image.blend(im1, im2, alpha=0.2) I get the result in Image 3 which is different from the result I am looking for (in the last image). How can I do that correctly?

thanks in advance.

This question doesn’t seem to be PyTorch-specific, so you might get a better answer in an image processing discussion board. In any case, I would check if morphological dilation and erosion could help narrowing down the mask a bit.

1 Like

What if you do a direct assignment of pixels instead of blending?
Something like below?

image1 = torch.randn(10,10) # 1st image
image2 = torch.randn(10,10) # 2nd image
image1[image2 > 0] = image2[image2>0]
1 Like