## 2 Materials and Methods
### Image Processing  
The chain stores' coffee grinders have 5 grinding settings, such as extra-fine, fine, medium, coarse, and extra-coarse, which can grind a variety of different flavors of coffee. When a burr with a specific level of wear is installed, all 5 grinding settings on the coffee grinder are adjusted to collect the coffee granules produced at each setting. With 3 wear levels of grinder burr and 5 grinding settings, there are 15 grinding situations in total. By adjusting all 5 grind settings, several burrs with the same degree of wear were used to produce coffee granules. A total of 200 images of coffee granules with a size reference coin were collected for each burr wear level. Therefore, for 3 burr wear levels, 600 images in total were collected for image processing to extract unified granule size distributions for training and testing the deep learning model. To be able to operate conveniently inside the coffee shop, the following method, which does not require excessive accuracy, is used to prepare coffee granule images. First, one grinds five coffee beans with the target coffee grinder and puts coffee granules on a white paper together with a size reference coin with a diameter of 20 mm. Then, one use the camera on a mobile phone with flash to take pictures of them at a distance of 20 cm plus or minus 5 cm to obtain the image. Using flash when taking photos at close range can make the ambient brightness more consistent. Therefore, a coffee shop clerk can easily prepare the image for the wear classification of grinder burrs. In order to obtain the size distribution of coffee granules from the images, we need to perform a granule size distribution analysis in the image processing. As images of the coffee granules can be taken at different distances and angles, a coin with a known size is used as a reference to estimate every coffee granule size in all taken images and perform the image processing together. When shooting, the coin is taken as a size reference in the image, so the actual area size of the coffee granules can be calculated from the proportional relationship between the actual area size of the coin and the number of pixels occupied by the coin in the image. For example, if a coin has an area of \(100\pi\) mm\({}^{2}\) and occupies 100 pixels in the processed image, we know that the ratio of the number of pixels of the object in the processed image to the actual size of the object is \(1:\pi\). Therefore, we can calculate each coffee granule area by multiplying the pixel number occupied by each coffee granule and \(\pi\), as shown in Figure 1.  
Figure 1: (**a**) Raw image of coffee granules and size reference coin; (**b**) coffee granules size estimations based on the size of the reference coin. In practice, the coffee granules could overlap or touch each other or have tiny holes. To handle these mentioned problems, further noise reduction and morphological operations such as erosion, dilation, opening, and closing should be properly performed to process the images before they can be used to estimate coffee granule sizes. The morphological operations [8] can be performed on both grayscale images and binary images. For grayscale images, the grayscale erosion [8] of an image involves assigning to each pixel the minimum value found over the neighborhood of the structuring element (kernel) to reduce the brightness. On the contrary, the grayscale dilation [8] of an image involves assigning to each pixel the maximum value found over the neighborhood of the structuring element; dilating bright regions also erodes dark regions. The grayscale opening [8] of an image involves performing a grayscale erosion followed by grayscale dilation to remove bright spots isolated in dark regions and to smooth boundaries; meanwhile, the grayscale closing [8] operation consists of a grayscale dilation followed by a grayscale erosion to remove dark spots isolated in bright regions and to smooth boundaries.