title: Failing to overlapp pictures of different sizes with OpenCV
body: <p>I am currently trying to familiarize myself with the field of computer vision. For a smaller university project I have to overlap pictures of a different size. For this I use OpenCV in Python and have tried to follow this <a href="https://docs.opencv.org/master/d0/d86/tutorial_py_image_arithmetics.html" rel="nofollow noreferrer">tutorials</a>.</p>
  <p>As you can see here, the overlapping works quite well for <a href="https://i.stack.imgur.com/CjJ5w.jpg" rel="nofollow noreferrer">colored images</a> (I used some fantasy wallpapers for that). However, I still fail with <a href="https://i.stack.imgur.com/rtrqE.png" rel="nofollow noreferrer">black and white images</a>. The overlaid fingerprints should look as if they were naturally overlaid, as it does with the colored image.</p>
  <p>Since I'm still new to the field of computer vision, I don't yet know what the problem is with the overlapping of the images and I would be happy if someone explains to me what the problem is and how to fix it. My source code is shown below.</p>
  <pre><code>background = cv2.imread(&quot;./background.png&quot;)
  overlay = cv2.imread(&quot;./overlay.png&quot;)
  rows_new, cols_new, channels = overlay.shape
  small_img = cv2.resize(overlay,(300,300))
  roi = background[0:300, 0:300]
  img2gray = cv2.cvtColor(small_img,cv2.COLOR_BGR2GRAY)
  ret, mask = cv2.threshold(img2gray, 200, 255, cv2.THRESH_BINARY)
  mask_inv = cv2.bitwise_not(mask)
  img1_bg = cv2.bitwise_or(roi,roi,mask = mask_inv)
  img2_fg = cv2.bitwise_or(small_img,small_img,mask = mask)
  dst = cv2.add(img1_bg,img2_fg)
  background[0:300, 0:300] = dst
  </code></pre>