title: Python and opencv: how do I convert the ALL of the background of this image to one colour or transparent
body: <p>I created the following image (image 3) using a threshold mask (image 2) on image 1. I am trying to convert all the pixels outside of the central image of image 3 (of lungs) to one colour (for example black) using opencv. Basically so that I am left with just the image of the lungs against a uniform background (or even transparent). My problem has been the similarity of the very outer pixels to those inside the lungs on image 3. Is this possible to do using opencv?</p>
  
  <p><a href="https://i.stack.imgur.com/Y7woM.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Y7woM.jpg" alt="IMAGE 1"></a></p>
  
  <p><a href="https://i.stack.imgur.com/BVh0l.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BVh0l.png" alt="IMAGE 2"></a></p>
  
  <p><a href="https://i.stack.imgur.com/RXnwb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RXnwb.png" alt="IMAGE3"></a></p>