title: Identify visible stones in the image - Any Approach in OpenCV & Deeplearning
body: <p>I have samples images of stones present in the images. I need to identify the visible stones only. The approach which I tried is <strong>threshold based filtering and detecting cv2.contours</strong>. Also, I am looking into <strong><a href="https://arxiv.org/abs/1606.02147" rel="nofollow noreferrer">ENet Architecture</a></strong> for semantic segmentation based deep learning approach. The samples images are below. <br />
  <strong>Example image1:</strong>
  <a href="https://i.stack.imgur.com/jADsf.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jADsf.jpg" alt="enter image description here" /></a>
  <strong>Example image2:</strong>
  <a href="https://i.stack.imgur.com/j1w3B.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/j1w3B.jpg" alt="enter image description here" /></a></p>
  <p>The code which I tried for contour based detection is as below</p>
  <pre><code>image = cv2.imread(os.path.join(img_path, img_name2))
  # threshold based customization
  lower_bound = np.array([0, 0, 0])
  upper_bound = np.array([250,55,100])
  
  hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
  #masking the image using inRange() function
  imagemask = cv2.inRange(hsv, lower_bound, upper_bound)
  plt.figure(figsize=(20,10)) 
  plt.imshow(imagemask, cmap=&quot;gray&quot;)
  # erode and diluation to smoothen the edeges
  final_mask = cv2.erode(imagemask, np.ones((3, 3), dtype=np.uint8))
  final_mask = cv2.dilate(imagemask, np.ones((5, 5), dtype=np.uint8))
  # find contours based on the mask
  contours = cv2.findContours(final_mask.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
  # draw contours
  img_conts = cv2.drawContours(image.copy(), contours[0], -1, (0,255,0), 3)
  
  plt.figure(figsize=(20,10)) 
  plt.imshow(img_conts, cmap=&quot;gray&quot;)
  </code></pre>
  <p>The sample contours ouput. I know that the thresholds can be tuned for better results here. <a href="https://i.stack.imgur.com/r5m33.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/r5m33.png" alt="enter image description here" /></a></p>
  <p>But, what I am looking here for the any better approach or solution can work in this heavy environment for detection small particles like stones. Any ideas to solve in better way?</p>