title: Python OpenCV: remove border from image
body: <p>Let's say I have an image like this:</p>
  
  <p><a href="https://i.stack.imgur.com/ToXYE.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ToXYE.jpg" alt="enter image description here"></a></p>
  
  <p>For which I want to remove the border and get this:</p>
  
  <p><a href="https://i.stack.imgur.com/0ZIoQ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0ZIoQ.jpg" alt="enter image description here"></a></p>
  
  <p>So exactly the same image, without the border. </p>
  
  <p>I found a "hacky" way to do it which finds the outer contour and draws a line over it... To be honest it's not the best way because I need to adjust the "thickness" of the line so that it is thick enough to cover up the border, but not too thick so it doesn't cover any of the circles.</p>
  
  <p>The <code>image</code> variable is the image you see above (already grayscaled, thresholded).</p>
  
  <pre><code>cnts = cv2.findContours(image, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
  cnts = cnts[0] if imutils.is_cv2() else cnts[1]
  cv2.drawContours(image, cnts, -1, 0, 15) # 15 is the right thickness for this image, but might not be for other ones...
  </code></pre>
  
  <p>The results is the 2nd picture above. Works great, but it doesn't work for ALL images (because of different thickness). Is there a better way to do this?</p>