How to paste one image to another one, by forcing the former's background as transparent?

imgBlack=Import["https://i.stack.imgur.com/KdDgSs.png"];
imgRed=Import["https://i.stack.imgur.com/wOPPys.png"];
ImageCompose[imgRed,RemoveBackground[imgBlack]]  

enter image description here


The threshold mentioned by @C.E. can also be used with RemoveBackground to remove the white edge.

Module[
 {img1, img2},
 {img1, img2} = Import /@ {
    "https://i.stack.imgur.com/KdDgSs.png",
    "https://i.stack.imgur.com/wOPPys.png"};
 ImageCompose[
  img2,
  RemoveBackground[img1, {White, 0.5}]]
 ]

Mathematica graphics


The definition of the function ColorReplace[img, color] is that it takes colors that are similar to (not exactly the same as) color and replaces those pixels with transparent pixels.

i1 = Import["https://i.stack.imgur.com/wOPPys.png"];
i2 = Import["https://i.stack.imgur.com/KdDgSs.png"];
i1 = ColorReplace[i1, White];
i2 = ColorReplace[i2, White];
ImageCompose[i1, i2]

Mathematica graphics

You may notice that there are still some white pixels around the black figure. We can fix that by providing our own threshold for how far away a color can be from white and still be considered similar:

i2 = ColorReplace[i2, White, 0.5];
ImageCompose[i1, i2] 

Mathematica graphics