title: How to fill a contour plot mask and retain data inside the contour and blackout the rest
body: <p>I have an image like so,
  <a href="https://i.stack.imgur.com/YYbMH.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YYbMH.jpg" alt="enter image description here" /></a></p>
  <p>By using the following code,</p>
  <pre><code>import numpy as np
  import cv2
  
  # load the image
  image = cv2.imread(&quot;frame50.jpg&quot;, 1)
  
  #color boundaries [B, G, R]
  lower = [0, 3, 30]
  upper = [30, 117, 253]
  
  # create NumPy arrays from the boundaries
  lower = np.array(lower, dtype=&quot;uint8&quot;)
  upper = np.array(upper, dtype=&quot;uint8&quot;)
  
  # find the colors within the specified boundaries and apply
  # the mask
  mask = cv2.inRange(image, lower, upper)
  output = cv2.bitwise_and(image, image, mask=mask)
  
  ret,thresh = cv2.threshold(mask, 50, 255, 0)
  if (int(cv2.__version__[0]) &gt; 3):
      contours, hierarchy = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
  else:
      im2, contours, hierarchy = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
  
  if len(contours) != 0:
      # find the biggest countour (c) by the area
      c = max(contours, key = cv2.contourArea)
      x,y,w,h = cv2.boundingRect(c)
      ROI = image[y:y+h, x:x+w]
  cv2.imshow('ROI',ROI)
  cv2.imwrite('ROI.png',ROI)
  
  cv2.waitKey(0)
  </code></pre>
  <p>I get the following cropped image,</p>
  <p><a href="https://i.stack.imgur.com/y8aZf.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/y8aZf.jpg" alt="enter image description here" /></a></p>
  <p>I would like to retain all data within the orange hand-drawn boundary including the boundary itself and blackout the rest.
  In the image above the data outside the orange boundary is still there. I do not want that. How do i fill the mask which is like this now so that i can retain data inside the orange boundary,</p>
  <p><a href="https://i.stack.imgur.com/QTLUw.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QTLUw.jpg" alt="enter image description here" /></a></p>
  <p>I would still like to retain other properties like the rectangular bounding box. I don't want anything else to change. How do I go about this?
  Thanks.</p>