title: How to properly insert mask into original image?
body: <p>My goal is to cover a face with circular noise (salt and pepper/black and white dots), however what I have managed to achieve is just rectangular noise.</p>
  <p>Using this image:
  <a href="https://i.stack.imgur.com/t7GJE.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/t7GJE.jpg" alt="like_this.jpg" /></a></p>
  <p>I found the face coordinates (x,y,w,h) = <code>[389, 127, 209, 209]</code>
  And using this <a href="https://github.com/ArtLabss/open-data-anonimizer/blob/main/anonympy/images/core.py" rel="nofollow noreferrer">function</a> added noise <br>Like:</p>
  <pre class="lang-py prettyprint-override"><code>img = cv2.imread('like_this.jpg')
  x,y,w,h = [389, 127, 209, 209]
  
  noised = add_noise(img[y:y+h,x:x+w])
  new = img.copy()
  new[y:y+h,x:x+w]  = noised
  
  cv2.imshow('new', new)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/T6hyY.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/T6hyY.jpg" alt="new.jpg" /></a></p>
  <p>From <code>x,y,w,h</code> I found that I want my circle to be at <code>(493, 231)</code> with radius 105</p>
  <p>I researched I found something about masking and bitwise operations, so I tried:</p>
  <pre><code>mask = np.zeros(new.shape[:2], dtype='uint8')
  cv2.circle(mask, (493, 231), 105, 255, -1)
  
  new_gray = cv2.cvtColor(new, cv2.COLOR_BGR2GRAY)
  masked = cv2.bitwise_and(new_gray, new_gray , mask=mask)
  
  cv2.imshow('masked', masked)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/aF3gw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aF3gw.png" alt="masked.jpg" /></a></p>
  <p>Here, the problem arises:</p>
  <pre class="lang-py prettyprint-override"><code>img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  OR = cv2.bitwise_or(masked, img_gray) # removes the black dots, idk why 
  
  cv2.imshow('bitwise - OR', OR)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/gaCOF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gaCOF.png" alt="enter image description here" /></a></p>
  <p>The black dots get removed from the noise and besides that, I can't seem to convert <code>OR</code> back to BGR.</p>
  <p>Maybe there is a better way to do that.</p>
  <p>Please, help/guidance needed!</p>