When making a program to count seeds, the contrast is poor on the image: And a Backlight isn't possible.
Tried the following WaterShed Algorithms:
- https://stackoverflow.com/questions/25789278/coffee-beans-separation-algorithm
- https://codegolf.stackexchange.com/q/40831/71194
- https://www.pyimagesearch.com/2015/11/02/watershed-opencv/
Without success, due to the poor contrast and shadow between the Seeds.
To improve remove the shadow between the seeds, GrabCut was tried.
import numpy as np
import cv2
from matplotlib import pyplot as plt
img = cv2.imread("C:\\image\\img.bmp")
mask = np.zeros(img.shape[:2],np.uint8)
bgdModel = np.zeros((1,65),np.float64)
fgdModel = np.zeros((1,65),np.float64)
rect = (0,0,1023,767)
cv2.grabCut(img,mask,rect,bgdModel,fgdModel,5,cv2.GC_INIT_WITH_RECT)
mask2 = np.where((mask==2)|(mask==0),0,1).astype('uint8')
img = img*mask2[:,:,np.newaxis]
cv2.imshow('Imagem', img)
cv2.waitKey(0)
cv2.imwrite('C:\\Users\\Desktop\\teste\\resultado.jpg', img)
plt.imshow(img),plt.colorbar(),plt.show()
And the following result:
Question
It wasn't possible to remove the shadows between the seeds, to improve the performance of the watershed algorithm. Is there a better way to remove the sadhows between objects?