Identify visible stones in the image - Approach in OpenCV & Deeplearning

I have samples images of stones present in the images. I need to identify the visible stones only. The approach which I tried is threshold based filtering and detecting cv2.contours. Also, I am looking into ENet Architecture for semantic segmentation based deep learning approach. The samples images are below.

Example image1: Example image2:

The code which I tried for contour based detection is as below

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=gray)
# 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=gray)

The sample contours ouput. I know that the thresholds can be tuned for better results here.

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? It would be great if anyone has ideas to solve in better way. Thanks in advance for this community for helping.

Topic semantic-segmentation image-segmentation opencv computer-vision deep-learning

Category Data Science

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.