title: How to remove multiple polygons using Opencv python
body: <p>Hi StackOverflow team, </p>
  
  <p>I have an image and I want to remove many portions/parts from the image. I tried to use the below code taken from <a href="https://stackoverflow.com/questions/48301186/cropping-concave-polygon-from-image-using-opencv-python?answertab=votes#tab-top">Cropping Concave polygon from Image using Opencv python</a></p>
  
  <p>Assume I have this image <a href="https://i.stack.imgur.com/VpQZp.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VpQZp.jpg" alt="Lena Image"></a>. Also, I have multiple polygons (such as rectangular shapes or any form of a polygon) from the image achieved via lebelme annotation tool. So, I want to remove those shapes from the images or simply changing their pixels to white. </p>
  
  <p>In other words, Labelme Tool will give you a dictionary file, where the dictionary has a key consisting of the points of each portion/polygon/shape)</p>
  
  <p>Then the polygon points can be easily extracted from the dictionary file. After points are extracted, we can define our points by giving names (e.g a,b,s...h), and each one is in this multidimensional format "[[1526, 319], [1526, 376], [1593, 379], [1591, 324]]"</p>
  
  <p>Here I thought of whitening each region. but whitening of multidimensional array seems to be unreliable.  </p>
  
  <pre><code>import numpy as np
  import cv2
  import json
  
  with open('ann1.json') as f:
      data = json.load(f)
  
  #%%
  a = data['shapes'][0]['points']; b = data['shapes'][1]['points']; c = data['shapes'][2]['points']; 
  #%%
  img = cv2.imread("lena.jpg")
  pts = np.array(a) # Points
  
  #%%
  ## (1) Crop the bounding rect
  rect = cv2.boundingRect(pts)
  x,y,w,h = rect
  croped = img[y:y+h, x:x+w].copy()
  
  ## (2) make mask
  pts = pts - pts.min(axis=0)
  
  mask = np.zeros(croped.shape[:2], np.uint8)
  cv2.drawContours(mask, [pts], -1, (255, 255, 255), -1, cv2.LINE_AA)
  
  ## (3) do bit-op
  dst = cv2.bitwise_and(croped, croped, mask=mask)
  
  ## (4) add the white background
  bg = np.ones_like(croped, np.uint8)*255
  cv2.bitwise_not(bg,bg, mask=mask)
  dst2 = bg+ dst
  
  #cv2.imwrite("croped.png", croped)
  #cv2.imwrite("mask.png", mask)
  #cv2.imwrite("dst.png", dst)
  cv2.imwrite("dst2.png", dst2)
  </code></pre>
  
  <p>Using Lena I have this output <a href="https://i.stack.imgur.com/GHhZO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GHhZO.png" alt="dst2 image"></a>. 
  But I need to go further and whiten other points/polygons, for example, the eyes. </p>
  
  <p>As you can see my code can use only one polygon points. I tried appending two other polygon points in my case the two eyes and got <a href="https://i.stack.imgur.com/CJ9wf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CJ9wf.png" alt="dst2"></a>. </p>
  
  <p>By appending, I mean I added the multidimensional points (e.g. pts = np.array(a+b+c)). </p>
  
  <p>In short, having an image is there a short way to remove these multiple polygons from the image (by keeping the dimensions of the image) using OpenCV and python.</p>
  
  <p>Json File: 
  <a href="https://drive.google.com/file/d/1UyOYUVMHpu2vBBEdR99bwrRX5xIfdOCa/view?usp=sharing" rel="nofollow noreferrer">https://drive.google.com/file/d/1UyOYUVMHpu2vBBEdR99bwrRX5xIfdOCa/view?usp=sharing</a></p>