Introduction - If you have any usage issues, please Google them yourself
Morphology on the following image processing, to eliminate the non-uniformity of illumination, and then binarization, the binary image processing with the morphology, the number of grains in the image statistics.