title: How to seperate the contours?
body: <p>This is the input image from which mask is being generated.</p>
  <p><img src="https://i.stack.imgur.com/i3PNZ.jpg" alt="Input Image" /></p>
  <p>I am getting an image mask as output from deep learning model and I am trying to get contours like in this image. The contours I am expecting should be of same height preferably most common found height among the contours and should be parallel.</p>
  <p><img src="https://i.stack.imgur.com/IVIXv.jpg" alt="Expected Mask Image" /></p>
  <p>But the contours I am getting are overlapping like in this image.</p>
  <p><img src="https://i.stack.imgur.com/bx95O.jpg" alt="Output Mask Image" /></p>
  <p>Sometimes the contours are of different length and  at different heights.
  How to get the contours as in expected image? I tried a different kernel size but am finding it difficult to get.</p>
  <p>Below is the code I used to convert output obtained from deep learning model.</p>
  <pre><code>se1 = cv2.getStructuringElement(cv2.MORPH_RECT, (8,8))
  mask1 = cv2.morphologyEx(pred_col_mask.copy(), cv2.MORPH_OPEN, se1)
  
  se2 = np.ones((8,8),np.uint8)
  mask2  = cv2.dilate(mask1, se2)
  
  se3 = cv2.getStructuringElement(cv2.MORPH_RECT, (8,8))
  cleaned_out = cv2.morphologyEx(mask2, cv2.MORPH_OPEN, se3)
  
  cnts = cv2.findContours(cleaned_out.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
  cnts = imutils.grab_contours(cnts)
  </code></pre>