title: How can I get rid of internal contours? python
body: <p>I'm localizing light polluted areas in a photo from a satellite using cv2.findContours. Many of them are not entirely pollute internally, what I mean by that is they have black holes inside of them which shouldn't be considered part of the contours neither separate contours since I'm only contouring light polluted areas. When I started indexing the contours by size I noticed the black holes were treated as separate contours.</p>
  
  <p>Processed image
  <a href="https://i.stack.imgur.com/HLNhB.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HLNhB.jpg" alt="image description"></a></p>
  
  <p>As you can see, for example #0, #67 and #64 are classified as contoured areas even though they shouldn't be</p>
  
  <p>To find the contours I'm using</p>
  
  <pre><code># Reading image
  image_orig = cv2.imread("india_night.jpg")
  # Processing to make contours smoother
  image_gray = cv2.cvtColor(image_orig, cv2.COLOR_BGR2GRAY)
  image_blurred = cv2.GaussianBlur(image_gray, (5, 5), 0)
  image_blurred = cv2.dilate(image_blurred, None)
  _, image_threshold = cv2.threshold(image_blurred, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
  #sorting contours by size
  _, contours, _ = cv2.findContours(image_threshold, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
  contours = sorted(contours, key=cv2.contourArea)
  </code></pre>
  
  <p>My goal is to not classify these unpolluted areas as polluted ones</p>