Research on the Evaluation Method of Eggshell Dark Spots Based on Machine Vision

Dark spots, which are widely present in different species of eggs, not only significantly affect the appearance and reduce the commercial value of eggs, but also increase the safety hazards of edible eggs in view of that Salmonella can easily penetrate the eggshell at the location of dark spots. During the first 5 days after egg production, it is difficult to identify and evaluate dark spots on the eggshell surface under natural lighting conditions. Therefore, it is a great challenge to automatically classify commercial eggs according to the amount of dark spots at the initial stage. In this paper, a method based on machine vision was proposed for identifying and evaluating eggshell dark spots. First, the K-means clustering algorithm was used to segment the individual egg image on the production line in order to obtain the complete eggshell surface area; then, the unsharp masking method was used to enhance the dark-spot features so as to realize the recognition of dark spots; and finally, quantitative evaluation was conducted according to the amount of dark spots on the eggshell surface and the ratio of the dark-spot projected area. Our experimental results show that the proposed method is able to quickly and accurately calculate the distribution of dark spots and the ratio of the dark-spot projected area. Specifically, the processing speed of dark-spot image is 1 frame/0.5s, which is 960 times faster than the speed of manual marking (1 frame/480s), and the detection capacity of the experimental device is 3600 eggs/h. It provides an automated method for quantitatively examining dark spots on eggshells, a scientific tool for conducting further research on the formation mechanism of dark spots, as well as a technical means for the high-throughput online examination of egg quality.


I. INTRODUCTION
Eggshell dark spots refer to the irregular, watermark-like spots on the surface of eggshells. The dark spots are not visible to the naked eye when the eggs are just laid. Under the illumination of a LED light source, they are usually present as translucent spots. About 5d-14d after egg production, the dark-spot features will become prominent and stable [1], and appear visible to the naked eye under daylight conditions. Eggshell dark spots (also known as the eggshell translucency phenomenon), as a common quality problem, are widely found in different species of laying hens [2]. Earlier studies have shown that the main hazards The associate editor coordinating the review of this manuscript and approving it for publication was Tallha Akram . of dark spots are manifested in two aspects. One is that dark spots can affect the appearance of eggshells and reduce the commercial value of eggs [3], [4], the other one is that dark spots are prone to bacteria such as Salmonella and may negatively impact food safety [5]- [7]. The detection of dark spots is an important part of egg processing before delivery to the market. The traditional method of dark-spot detection is manual visual sorting, which is a high-intensity, tedious and unhygienic process. In recent years, many researchers have tried to develop automated methods for dark-spot detection and evaluation in order to reduce the labor intensity and improve the processing efficiency and accuracy.
As an important branch of artificial intelligence, machine vision has been widely used in various detection fields and has achieved great success due to its non-contact, real-time, objective, and low-cost characteristics. In order to automate the quality grading process of commercial eggs, researchers have conducted in-depth studies using the image processing and machine vision technology in the following research fields: dirt detection [8]- [10], crack detection [11]- [16], geometric parameter estimation [17]- [20], freshness estimation [21], automatic grading [22]- [24], etc. In terms of dark-spot detection and evaluation, literature [25] applied deep learning to detect eggs with dark spots, and achieved good accuracy in both the samples with dark spots and the samples of normal eggs. Specifically, the G component of the egg RGB image was enhanced to intensify the clarity of the dark spots. Then, 1200 images of dark-spot eggs and 1200 images of normal eggs were imported into the GoogleNet network for training. After 20 iterations, the overall detection accuracy rate reached 98.19%. Literature [1] collected 354 eggs from 600 395-day-old dwarf brown laying hens, and formulated a grading standard of eggshell dark spots (level 1-4) by using the gray recognition method and colorimetric method. The gray recognition method was mainly implemented by manual measurement of the darkspot density and area for each grade of eggs, which is a very complicated and time-consuming process. The colorimetric method refers to the process of manual measurement using a colorimeter, which is a relatively simple process, but may encounter problems while distinguishing between eggs of similar grades. In summary, since the dark-spot phenomenon was raised decades ago, there have been limited studies on the evaluation of egg quality based on dark spots, mainly because of the lack of effective methods for quantitative measurement. The automatic and intelligent research of dark-spot detection and evaluation is still in its infancy. This paper, by taking dark spotted eggs as the research object, proposed a novel method of dark-spot detection and quantitative evaluation based on machine vision, which overcame multiple shortcomings of the manual process such as high labor intensity, massive time consumption, and low precision. Our study provides an automated method for quantitatively examining dark spots on eggshells, a scientific tool for conducting further research on the formation mechanism and removal methods of dark spots, as well as a technical means for the high-throughput online examination of egg quality.

A. SELECTION OF EGGS
A total of 300 56-week-old laying hens (species: Jinghong and Jingbai), which were provided by Hebei Huanshan Agricultural Development Co., Ltd., were used in our study. All the hens were maintained at the same conditions throughout the experiment: enclosed henhouse, identical feeding conditions, and 16 hours of lighting. The average egg production rate is about 70%. In order to measure the amount and distribution of dark spots on the eggshells, a total of 416 eggs laid on the same day were collected from each species of hens and were placed on egg trays with digital labels. Then, the experimental eggs were selected according to the following conditions: weight between 45 and 60g; intact eggshell with no crack; no soft eggshell; no egg deformity; and no sandy eggshell (small calcifications on the eggshell surface). Eventually, 360 experimental eggs were selected. In order to make the contour lines of the dark spots clearer and more stable, the experimental eggs were kept under constant conditions (temperature between 20 • C and 25 • C; relative humidity between 50% and 60%) for 5 days before collecting the egg images. During the experiment, all animal-related procedures strictly followed the recommendations from the national and local animal welfare agencies.

B. IMAGE ACQUISITION METHOD
The image acquisition device is composed of three parts: the loading area, the image acquisition area and the classification area. The loading area is to adjust the interval between adjacent eggs on the conveyor belt to an appropriate distance and transport them to the image acquisition area. The image acquisition area is to capture egg images and conduct dark-spot measurement. The classification area is to classify the eggs according to the dark-spot measurement results. In order to enhance the dark spots on the egg surface, the image acquisition area is equipped with an LED cold light source (BS001, Dezhou Boshi Incubation Equipment Factory) to illuminate the egg on the chain egg roller from the bottom of the roller in the dark room, so that the CCD camera (HT-HT-UBD130C, Shenzhen Huateng Vision Technology Co., Ltd.) can capture clear dark-spot images. To balance the accuracy and speed of dark-spot detection, the image resolution is set to 396 * 297 pixels. The image acquisition device is composed of 3 conveying channels (see Figure 1(a) for the top view and Figure 1(b) for the sectional view of the overall structure). Two cameras are installed above each channel to obtain the A side and B side images of the same egg respectively. Below explains the image acquisition process for a single channel. First, after entering the image acquisition area, the egg will be transported horizontally by the chain egg roller into the dark room. When the egg passes directly below Camera-1, Camera-1 will capture the first image of the egg which is labeled as A side image. Then, the egg roller will contact with the friction plate below, and the friction will drive the egg roller to rotate around its axis, thereby making the egg to rotate as well. At the same time, the egg will be moved horizontally forward. When the egg reaches directly below Camera-2, it has been rotated by 180 • , and Camera-2 will capture another image of the egg which is labelled as B side image, as shown in Figure 1(c). Basically, the algorithm proposed in this paper realizes dark-spot measurement of the entire egg surface by separately counting the dark spots on A side and B side images. The average detection time of a single egg is 3s; the detection capacity of a single channel is 1200 eggs/h; and the detection capacity of the entire device is 3600 eggs/h.

III. DARK-SPOT DETECTION METHOD BASED ON MACHINE VISION A. IMAGE PREPROCESSING METHOD
The image acquisition device was designed to simulate the work flow of the egg grading process. The entire grading process is composed of three key links: feeding, image acquisition, and sorting. During image acquisition, the images of the eggs were taken during the transportation process following the egg rollers. Therefore, the background of the image would contain part of the conveying device. In order to facilitate subsequent statistical analysis, the background of the image must be removed first so as to obtain an image containing only the egg.
Otsu, grab cut, deeplab-v3 and K-mean algorithms have been widely used in different image segmentation fields [26]- [29]. In order to realize the segmentation of foreground and background in egg image, we used the same data to compare the segmentation algorithms of Otsu, Grab Cut, DeepLab-v3 and K-Means. The results are shown in Table 1.
Otsu is a segmentation algorithm based on boundary threshold. As the resemblance between the egg boundary and the acquisition device edge under strong light can lead to over-segmentation, the segmentation effect of Otsu is relatively poor. The graph-based segmentation algorithm Grab Cut has a good segmentation quality, but this algorithm involves manual interaction which greatly affects the working efficiency. Thus, Grab Cut is not suitable for unmanned scenarios. The deep learning based DeepLab-v3 segmentation algorithm has both a good segmentation quality and excellent anti-noise performance, but due to the operation complexity, this algorithm has a higher requirement on the computational resources. Comparatively, the K-means clustering algorithm has a satisfactory segmentation quality, a fast speed and low complexity, and was therefore considered the preferred method for achieving background segmentation. The core idea of the K-means clustering algorithm is to artificially select K initial clustering centers first, and then calculate the distances between each object and the K clustering centers (the clustering centers are randomly generated during the first iteration). Each object would be assigned to the clustering center that is closest to it. The clustering centers alongside the objects assigned to them constitute one cluster. After the assignment, the mean value of the K clusters is calculated as the new clustering center, and then a new round of assignment is performed. This process will be repeated continually until the K clustering centers no longer change.
In an acquired image, the egg was taken as the foreground, and the rest was considered background. The value of K was set to 2. The distance was calculated by the Euclidean distance formula, which is expressed as follows: where the value of n is 2, representing a 2D space; dist(X , Y ) represents the Euclidean distance between X (x 1 , x 2 ) and Y (y 1 , y 2 ). Since the original image is of a RGB format, the image information is represented by 3D data. Comparatively, the LAB color space is composed of the brightness (L), the green to red component (A), and the blue to yellow component (B), where the brightness (L) can be discarded, leaving A and B as the 2D data to calculate the Euclidean distance. Before segmenting an image through k-means, the image needs to be converted from the RGB color space to the LAB color space first. After implementing the K-means algorithm, two separate images will be obtained from the original image: the image of the egg is taken as the foreground; while the image without the egg is taken as the background. Our specially-designed dark-spot image acquisition device allows the dark-spot image collected under restricted conditions to have a single background, which satisfies the effectiveness of the k-means clustering algorithm for image segmentation. However, due to the randomness of the clustering centers, the classification results are also subject to a certain degree of randomness. Therefore, by calculating the color histogram of the two segmentation results, the following results were obtained. Due to the difference in egg size, the chain egg rollers might not be completely blocked by the eggs, so part of the egg roller would appear in the image in the form of a dynamic background. In order to obtain stable clustering centers to ensure the accuracy of the k-means algorithm for segmenting the foreground (egg) from the background (non-egg part), the range of pixel gray values of the clustering centers needs to be determined according to the histogram. Through repeated experiments, it was found that the gray scale of the background color concentrated between 0 and 100, and the grayscale values fell in the range of 200-250. The number of background pixel values was always lower than the number of foreground pixel values. By performing foreground and background segmentation according to the clustering centers as described above, the results shown in Figure 3 were obtained.

B. IMAGE ENHANCEMENT
In the egg image after removing the background, the contrast between dark spots and the normal eggshell has not satisfied the requirement of completely distinguishing the dark spots yet. Thus in this paper, the unsharp masking method was applied to further enhance the contrast of the dark spots. The core idea is to process the foreground image (the egg image with dark spots) to obtain a grayscale image I 0 first, and then to filter the grayscale image I 0 through a low-pass filter to further generate the passivated blurred image I 1 . By subtracting I 1 from I 0 (I 0 − I 1 ), image I 2 which retains the high-frequency components of dark spots is obtained. Then, I 2 is enlarged by a certain parameter and superimposed with the original image I 0 to eventually generate the dark-spot enhanced image.
While filtering the original image with the low-pass filter, the dark spots on I 0 , which belong to high-frequency components, are largely suppressed; therefore, the high-frequency components on the blurred image I 1 are greatly weakened, while the normal eggshell that mainly contains low-frequency components is not much affected. By subtracting the blurred image from the original image (I 0 − I 1 ), many low-frequency components in I 0 are removed, while high-frequency components (dark spots) are mostly retained. Subsequently, by further enlarging the high-frequency image I 2 with parameter X and superimposing it with the original image I 0 (I 3 = I 0 + x * I 2 ), image I 3 is obtained.
In image I 3 , the dark spots (high-frequency components) are enhanced, while the normal eggshell around the dark spots (low-frequency components) is almost not affected. The specific dark-spot detection process is shown in Figure 4: For the no ringing characteristic, Gaussian low-pass filter can be used to strictly control the cutoff frequency transition between the dark spots (high frequency) and the normal eggshell around the dark spots (low frequency). Therefore in this paper, a Gaussian low-pass filter was applied to generate the blurred image I 1 from the original image I 0 . The 2D form of this filter is expressed as follows: where D(u,v) represents the distance from the center of the frequency rectangle, and D 0 represents the cutoff frequency. When D(u,v) = D 0 , GLPF will decline to 0.607 of its maximum value. If D 0 is either too large or too small, the enhancement effect of dark spots will be affected. Through experiments, it was determined that D 0 = 30 could achieve the best filtering effect for I 1 , as shown in Figure 5. While calculating I 3 (I 3 = I 0 + x * I 2 ), the choice of parameter X is extremely important. In order to enhance the dark-spot features in a nonlinear manner (i.e., enhancing the pixel values of dark spots (x = enhancement coefficient) while remaining the original status for the normal eggshell (x = 1)), the value of X was determined by a piecewise function. Figure 6 shows the enhancement effect of the egg image with different enhancement coefficients. It can be seen that the image features become more obvious as the enhancement coefficient increases. However, if the enhancement coefficient is too large, there will be some noises that may affect the experimental results. After repeated experiments, the enhancement coefficient of 7.5 was finally selected for image enhancement before binarization.

C. DARK-SPOT IMAGE BINARIZATION
The binary map can more clearly visualize the distribution of dark spots on the eggshell, and therefore facilitate the subsequent calculations while reducing the time complexity. To binarize the enhanced grayscale image I 3 , it was experimentally determined that w (threshold value) = 0.98 could lead to the most qualified binary image, as shown in Figure 7(e).

D. DARK-SPOT EVALUATION
The evaluation of dark spots was mainly carried out based on two indicators, the amount of dark spots and the ratio of the dark-spot projected area. Since the dark spots are mostly irregular polygons, it is difficult to count the amount of dark spots from a geometric perspective. In the 2D image, the pixels within an eight-connected region belong to the same object. In this paper, dark-spot evaluation was implemented by calculating the number of eight-connected regions in the binary image.
The ratio of the dark-spot projected area in the 2D image is equivalent to the ratio of the white pixels representing the dark spots in the binary image to the total pixels of the projected area of the entire egg. In addition, during the calculation of the area, the number of white pixels on the outer contour of the eggshell needs to be subtracted from the number of dark-spot pixels in order to ensure the accuracy of the results.

IV. MANUAL DETECTION OF DARK SPOTS A. DARK-SPOT MARKING ON THE EGGSHELL SURFACE
The manual processing of dark-spotted eggs also requires illumination from a strong light source in order to visualize the dark spots. The egg image taken under the illumination   of strong light source was imported into Photoshop and enlarged by a certain multiple until the dark spots were clearly displayed. Then, the brush tool was used manually to mark the dark spots with a high-contrast color (the same color was used for all egg samples, color value: #6951fc). The final effect of dark-spot marking is shown in Figure 8.

B. DARK-SPOT EVALUATION
In order to evaluate the quality of dark-spotted eggs more objectively, the manual detection process also took the amount of dark spots and the ratio of the dark-spot projected area as the two indicators for egg quality evaluation. First, the manually marked egg image was imported into Matlab   to generate the grayscale image. Since the dark spots had been marked by the same color, all the dark spots had the same gray value, which was 108 on the grayscale image. During dark-spot extraction, all the pixels with the gray value of 108 were extracted (i.e., the pixels with the gray value of 108 were set to 255, while the remaining pixels were set to 0) to obtain the binary image containing only dark spots. Finally, the number of the white eight-connected regions was calculated as the number of dark spots, and the ratio of the area of white pixels in the dark-spot regions to the total  pixels of the egg projected area was calculated as the ratio of the dark-spot projected area. The specific process is shown in Figure 9.

V. COMPARISON OF METHODS
A total of 50 dark-spotted egg images of different severities were selected from the experimental samples as the control data for the comparison between the machine vision method and the manual method. Based on the data of manual marking as the benchmark, the two indicators mentioned above (the amount of dark spots and the ratio of the dark-spot projected area to the entire egg projected area) were compared and the following results were obtained.
It can be seen from the results that, for the ratio of the dark-spot projected area, the results of the manual method and the machine vision method exhibit a high degree of fit; for the amount of dark spots, the manual method shows a lower value than the machine vision method, but the distribution trend remains the same. Therefore, our proposed machine vision method is proven effective.

VI. DISCUSSIONS
When machine vision is used for classification, the cleanliness of the eggshell surface is an important factor that affects the detection results of dark spots. Therefore, the feed powders, dusts and stains on the surface of the eggshell must VOLUME 8, 2020 be cleaned as far as possible before classification in order to avoid any negative impact on the detection accuracy caused by mistaken or missing recognition of dark spots. Since the eggshell has a 3D elliptic surface, the dark spots on the contour of the egg will be compressed into a strip shape. While calculating the ratio of the dark-spot projected area, the projected area calculated from 2D image is smaller than the actual situation. For the subsequent research, we will study the 3D reconstruction of the egg in order to accurately reflect the surface of the eggshell. Due to the limitations of manual operation, the manually marked images may involve various deficiencies, such as missed dark spots, inaccurate marking of boundary, discontinuous marking of dark-spot area, etc.; therefore, the amount of dark spots detected by the manual method is lower than that of the machine vision method. Generally speaking, neglect or mislabeling of very small dark spots would not significantly affect the results of the ratio of the dark-spot projected area, so this indicator shows a higher degree of fit between the manual method and the machine vision method. The manual detection of an egg image takes 8 minutes on average, while the machine vision method takes less than 0.5s, which improves the detection efficiency by 960 times. In summary, the superiority of machine vision detection is confirmed in terms of both the detection accuracy and detection speed.

VII. CONCLUSION
This paper proposed a detection method of eggshell dark spots based on machine vision. First, the K-means clustering algorithm was used to segment the individual egg image on the production line in order to obtain the complete eggshell surface area; then, the unsharp masking method was used to enhance the dark-spot features; and finally, quantitative evaluation was conducted according to the amount of dark spots on the eggshell surface and the ratio of the dark-spot projected area. Our experimental results show that the proposed method is able to quickly and accurately calculate the distribution of dark spots and the ratio of the dark-spot projected area. Specifically, the processing speed of dark-spot image is 1 frame/0.5s, which is 960 times faster than the speed of manual marking (1 frame/480s), and the detection capacity of the experimental device is 3600 eggs/h. Overall, this method overcomes the high subjectivity problem of manual detection and greatly improves the detection accuracy. It provides an automated method for quantitatively examining dark spots on eggshells, a scientific tool for conducting further research on the formation mechanism and removal methods of dark spots, as well as a technical means for the high-throughput online examination of egg quality.