title: How to remove the white border/edge around a figure in an image using python?
body: <p>I want to remove the white border between the black mask and the body image</p>
  
  <p>Image input examples: </p>
  
  <p><a href="https://i.stack.imgur.com/4rN1l.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4rN1l.png" alt="enter image description here"></a></p>
  
  <p>Image output with thickness 1:</p>
  
  <p><a href="https://i.stack.imgur.com/0LA0F.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0LA0F.png" alt="enter image description here"></a></p>
  
  <p>Image output with thickness 2:</p>
  
  <p><a href="https://i.stack.imgur.com/nyAXr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nyAXr.png" alt="enter image description here"></a></p>
  
  <p>I tried some games with Blur and thresholds that I found in here
  I also used this code to find and draw the contour </p>
  
  <pre class="lang-py prettyprint-override"><code>    thickness = 3
      image = cv2.imread('../finetune/22.png')
      blank_mask = np.zeros(image.shape, dtype=np.uint8)
      gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
  
      cnts = cv2.findContours(gray, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
      cnts = cnts[0] if len(cnts) == 2 else cnts[1]
  
      cv2.drawContours(image, cnts, -1, (255,0,0), thickness)
      cv2.imshow('image', image)
      cv2.imwrite('../finetune/22-'+str(thickness)+'r.png',image)
      cv2.waitKey()
  </code></pre>
  
  <p>However the contour I've found is the black mask edge and not the white line
  I played with the thickness and it works  nice but on each image this contour is different, also the thickness is not equal throughout the figure</p>
  
  <p>what is the best precise way to remove it?</p>