A stain detection method for fresh egg cleaning

By dynamically adjusting the window size of pixel points in the fresh egg grayscale image, and using gradient direction entropy and local geometric direction consistency to calculate the segmentation threshold, the problem of the normal eggshell edge being mistakenly recognized as a stain in the Sauvola algorithm is solved, achieving high accuracy of fresh egg stain detection.

CN120259310BActive Publication Date: 2025-07-25EGG NO 1 FOOD CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510741877.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-06-05
Publication Date
2025-07-25
Estimated Expiration
2045-06-05

AI Technical Summary

Technical Problem

When identifying stains on fresh eggs, the existing Sauvola adaptive threshold segmentation algorithm cannot dynamically adjust the size of the neighborhood window of pixels, resulting in the edge of normal eggshell being misidentified as a stain, reducing the accuracy of stain detection.

Method used

By obtaining the gradient direction angle of each pixel point in the fresh egg grayscale image, dynamically adjusting the window size of the pixel point, using the gradient direction entropy and local geometric direction consistency to calculate the target window of each pixel point, combining the gray scale mean and standard deviation to calculate the segmentation threshold, accurately distinguishing the stained area and the normal eggshell area.

Benefits of technology

It improves the accuracy of stain detection results of fresh egg grayscale images, avoids misidentification of the edges of normal eggshells, and ensures the accuracy of stain detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120259310B_ABST
    Figure CN120259310B_ABST
Patent Text Reader

Abstract

The present invention relates to the technical field of image data processing. More specifically, the present invention relates to a stain detection method for fresh egg cleaning. The method includes: determining the gradient direction entropy of a pixel point according to the sum of entropy values of the number of pixel points in each gradient direction angle interval in the initial window of the pixel points in the fresh egg grayscale image; calculating the local geometric direction consistency of the pixel point according to the sum of the horizontal components and the sum of the vertical components of the gradient direction angles of all pixel points in the initial window of the pixel point; calculating the target window size of the pixel point; calculating the segmentation threshold of the pixel point according to the grayscale mean value and the grayscale standard deviation of all pixel points in the target window of the pixel point, and processing the fresh egg grayscale image according to the segmentation threshold of the pixel point to obtain the stain detection result of the fresh egg grayscale image, effectively improving the accuracy of the fresh egg stain detection result.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of image data processing. More specifically, the present invention relates to a stain detection method for fresh egg cleaning. Background Art

[0002] The stains on the surface of fresh eggs may come from feces and litter debris in the chicken coop environment, or impurities contaminated during storage and transportation. These stains not only affect the appearance of fresh eggs, but also may carry a large number of bacteria and microorganisms, contaminating the eggshell surface, and then invading the egg through the pores, accelerating the deterioration of fresh eggs, shortening the shelf life, and seriously affecting the edible safety and quality of fresh eggs. Therefore, after fresh eggs enter the processing factory from the farm, they need to be preliminarily detected before cleaning to evaluate the degree of stain contamination and formulate a cleaning strategy.

[0003] The Sauvola adaptive threshold segmentation algorithm is a classic algorithm for image binarization. This algorithm obtains the mean and standard deviation in the neighborhood window for each pixel point in the image, so as to accurately calculate the optimal threshold of the pixel point. The surface of fresh eggs is usually curved and has strong reflectivity, which easily leads to uneven illumination (such as the top of the eggshell being too bright, the side being too dark, and differences in eggshell color and texture). The Sauvola adaptive threshold segmentation algorithm can dynamically adapt to the brightness changes in different regions by locally calculating the threshold, avoiding misjudging the normal eggshell area as a stain when using the global threshold method under uneven illumination.

[0004] However, the Sauvola adaptive threshold segmentation algorithm uses a neighborhood window of a fixed size. When identifying the stains on the surface of fresh eggs, if the neighborhood covers both sides of the fresh egg edge, the gray mean value will be flattened, resulting in the possible misidentification of the normal edge of the fresh egg as a stain when segmenting the stain area on the surface of the fresh egg, reducing the accuracy of stain detection.

[0005] In summary, there is an urgent need for a detection method that can accurately and dynamically adjust the size of the neighborhood window of pixel points to accurately identify the stains on the surface of fresh eggs. Summary of the Invention

[0006] To solve the above technical problem of how to accurately and dynamically adjust the size of the neighborhood window of pixel points to accurately identify the stains on the surface of fresh eggs, the present invention proposes a stain detection method for fresh egg cleaning, which includes the following steps:

[0007] Obtain the gradient direction angle of each pixel point in the grayscale image of the fresh egg, divide the gradient direction angle into multiple intervals, and determine the gradient direction entropy of the pixel point according to the entropy sum of the number of pixel points in each interval in the initial window of the pixel point; calculate the local geometric direction consistency of the pixel point according to the sum of the horizontal components and the sum of the vertical components of the gradient direction angles of all pixel points in the initial window of the pixel point; calculate the Target window size of the pixel point :

[0008] ;

[0009] is the initial window size, and are respectively the abscissa indices of the th pixel point and the th pixel point in its initial window, and are respectively the ordinate indices of the th pixel point and the th pixel point in its initial window, and are respectively the local geometric direction consistency degrees of the th pixel point and the th pixel point in its initial window, is the gradient direction entropy of the th pixel point, is the exponential function with base e; calculate the segmentation threshold of this pixel point according to the grayscale mean and grayscale standard deviation of all pixel points in the target window of the pixel point, and process the fresh egg grayscale image according to the segmentation threshold of the pixel point to obtain the stain detection result of the fresh egg grayscale image.

[0010] The present invention can accurately obtain the stain detection result in the fresh egg grayscale image by dynamically adjusting the window size of each pixel point in the fresh egg grayscale image. When dynamically adjusting the window size of the pixel point, the present invention takes into account that the edge of the normal eggshell may be misidentified as a stain, and the degree of gradient direction chaos and the degree of gradient direction consistency between the stain and the edge of the eggshell are not the same. Therefore, when calculating the size of the target window of each pixel point, the present invention can accurately adjust the size of the initial window by respectively obtaining the gradient direction entropy of the pixel point in the initial window and the vector sum of the vertical direction component and the horizontal direction component of the gradient direction of each pixel point, and accurately obtain the size of the final window required for each pixel point, so as to accurately distinguish the stain area and the normal eggshell area on the surface of the fresh egg, and effectively improve the accuracy of the obtained stain detection result of the fresh egg grayscale image.

[0011] According to a stain detection method for fresh egg cleaning provided by the present invention, before obtaining the gradient direction angle of each pixel point in the fresh egg grayscale image, it further includes: photographing the surface of the fresh egg for preprocessing to obtain the fresh egg grayscale image; wherein the preprocessing includes at least image denoising and grayscale processing.

[0012] In view of the fact that when obtaining the grayscale image of fresh eggs, noise may exist in the obtained fresh egg image due to interference in the surrounding environment or electronic devices, the present invention preprocesses the surface photos of fresh eggs obtained by shooting, which can effectively improve the quality of the pictures.

[0013] According to a stain detection method for fresh egg cleaning provided by the present invention, the gradient direction angle is divided into multiple intervals, including: according to the preset number of intervals The gradient direction angle is divided into intervals.

[0014] According to a stain detection method for fresh egg cleaning provided by the present invention, determining the gradient direction entropy of the pixel point according to the entropy value sum of the number of pixel points in each interval in the initial window of the pixel point includes:

[0015] ;

[0016] is the gradient direction entropy of the pixel point, is the number of intervals of the gradient direction angle, is the number of pixel points in the initial window of the pixel point located in the th interval, is the logarithmic function with base e, is the linear normalization function.

[0017] The present invention takes into account that there are significant differences in the gradient directions between the eggshell edge and the stain area. The gradient direction of the eggshell edge has a lower degree of chaos, while the stain area has a higher degree of chaos due to its irregularity. Therefore, the present invention analyzes the value of the gradient direction angle in the initial window of the pixel point to obtain the gradient direction entropy of the pixel point, which is used as an important feature for evaluating whether the pixel point is in the stain area, so that the edge pixel points of the stain area can be accurately obtained based on this.

[0018] According to a stain detection method for fresh egg cleaning provided by the present invention, the acquisition methods of the horizontal component and the vertical component of the gradient direction angle of the pixel point include: taking the cosine function value of the gradient direction angle of the pixel point as the horizontal component of the pixel point, and taking the sine function value of the gradient direction angle of the pixel point as the vertical component of the pixel point.

[0019] According to a stain detection method for fresh egg cleaning provided by the present invention, calculating the local geometric direction consistency of the pixel point according to the sum of the horizontal components and the sum of the vertical components of the gradient direction angles of all pixel points in the initial window of the pixel point includes:

[0020] ;

[0021] is the local geometric direction consistency of the pixel point, is the initial window size, , are respectively the gradient magnitude and gradient direction angle of the pixel point in the initial window of the pixel point, 、 are respectively the horizontal component and vertical component of the gradient direction angle of the pixel point in the initial window of the

[0022] In the present invention, it is considered that the gradient direction of the pixel points in the initial window of the current pixel point can evaluate the vector direction of this pixel point. Therefore, by obtaining the vector directions of the pixel points in the initial window of the current pixel point and weighting them by the gradient magnitude of the pixel points, the edge of the eggshell area can be accurately highlighted based on this. The larger this value is, the greater the possibility of being the edge of the eggshell area.

[0023] According to a stain detection method for fresh egg cleaning provided by the present invention, calculating the segmentation threshold of the pixel point according to the gray mean value and gray standard deviation of all pixel points in the target window of the pixel point includes: rounding down the size of the target window of the pixel point to an odd integer to obtain the final window size of this pixel point;

[0024] ;

[0025] is the segmentation threshold of the pixel point, 、 are respectively the gray mean value and gray standard deviation of all pixel points in the final window of the pixel point, is the sensitivity coefficient.

[0026] In the present invention, it is considered that constructing the final window centered on the current pixel point can comprehensively consider the gray features around this current pixel point, so that the segmentation threshold of it can be accurately calculated. Therefore, when calculating the segmentation threshold of the pixel point after obtaining the target window of the pixel point based on the above steps, the size of the target window of the pixel point is rounded down to an odd integer, so that the surrounding features of this pixel point can be accurately evaluated according to the gray features around it, effectively improving the accuracy of the obtained segmentation threshold.

[0027] A stain detection method for fresh egg cleaning provided by the present invention, which processes the grayscale image of the fresh egg according to the segmentation threshold of the pixel points, includes: if the number of pixel points not higher than the segmentation threshold of the pixel point in the final window of the grayscale image of the fresh egg is greater than the number threshold, then the pixel point is a stain pixel point.

[0028] A stain detection method for fresh egg cleaning provided by the present invention, which processes the grayscale image of the fresh egg according to the segmentation threshold of the pixel points to obtain the stain detection result of the grayscale image of the fresh egg, includes: obtaining all the stain pixel points in the grayscale image of the fresh egg, and taking the connected domain of the stain pixel points as the stain in the grayscale image of the fresh egg.

[0029] A stain detection method for fresh egg cleaning provided by the present invention is characterized in that after obtaining the stain detection result of the grayscale image of the fresh egg, it further includes: sending a cleaning prompt for the fresh egg corresponding to the grayscale image with stains.

[0030] The present invention has the following beneficial effects:

[0031] Based on the above technical solution, for a stain detection method for fresh egg cleaning provided by the present invention, when obtaining the stain detection result on the surface of the fresh egg, by dynamically adjusting the window size of each pixel point in the grayscale image of the fresh egg, the stain detection result in the grayscale image of the fresh egg can be accurately obtained. When dynamically adjusting the window size of the pixel point, the present invention takes into account that the edge of the normal eggshell may be misidentified as a stain, and the degree of gradient direction chaos and the degree of gradient direction consistency between the stain and the edge of the eggshell are not the same. Therefore, when calculating the size of the target window of each pixel point, the present invention can accurately adjust the size of the initial window based on obtaining the gradient direction entropy of the pixel point in the initial window and the vector sum of the vertical direction component and the horizontal direction component of the gradient direction of each pixel point, and accurately obtain the size of the final window required for each pixel point, so as to accurately distinguish the stain area and the normal eggshell area on the surface of the fresh egg, effectively improving the accuracy of the stain detection result of the grayscale image of the fresh egg obtained. Description of the Drawings

[0032] Figure 1 is a flowchart of the steps of a stain detection method for fresh egg cleaning provided by an embodiment of the present invention;

[0033] Figure 2 is an example diagram of a grayscale image of a fresh egg provided by an embodiment of the present invention;

[0034] Figure 3 is a fresh egg stain detection result obtained without dynamically adjusting the neighborhood window size of the pixel point provided by an embodiment of the present invention;

[0035] Figure 4Schematic diagram of stain detection results of a fresh egg grayscale image obtained after dynamically adjusting the window size according to an embodiment of the present invention. Detailed implementation manners

[0036] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all of the embodiments.

[0037] An embodiment of the present invention discloses a stain detection method for fresh egg cleaning. This method can dynamically adjust the neighborhood window size of pixel points in the Sauvola adaptive threshold segmentation algorithm according to the change characteristics of pixel points in the fresh egg grayscale image, so as to accurately divide the stain area on the surface of the fresh egg.

[0038] Specifically, please refer to Figure 1 , Figure 1 which is a step flowchart of a stain detection method for fresh egg cleaning provided by an embodiment of the present invention. This method includes the following steps:

[0039] S1: Obtain a fresh egg grayscale image.

[0040] Exemplarily, in an embodiment of the present invention, before obtaining the gradient direction angle of each pixel point in the fresh egg grayscale image, it further includes: taking a photo of the fresh egg surface for preprocessing to obtain a fresh egg grayscale image.

[0041] Among them, the preprocessing includes at least image denoising and grayscale processing, and may also include image equalization processing, contrast enhancement, etc., which can be specifically set according to actual needs.

[0042] It can be understood that the initially collected photo of the fresh egg surface is a colored and possibly noisy image. Therefore, before obtaining the stain detection result on the fresh egg surface, it is necessary to first perform preprocessing such as grayscale conversion and denoising on the photo of the fresh egg surface.

[0043] The fresh egg grayscale image obtained after preprocessing can be seen in Figure 2 shown as Figure 2 which is an example diagram of a fresh egg grayscale image provided by an embodiment of the present invention. As can be seen from Figure 2 , the collected fresh egg grayscale image generally includes a bright eggshell area, a stain and background area with a lower gray level. The edge of the eggshell area is connected to the background area, and the stain area exists in the eggshell area.

[0044] The conventional Sauvola adaptive threshold segmentation algorithm does not dynamically adjust the neighborhood window size of pixel points, and the directly processed stain area may divide the normal fresh egg edge into the stain area. Specifically, please refer to Figure 3 shown as Figure 3The fresh egg stain detection result obtained without dynamically adjusting the neighborhood window size of pixel points provided by the embodiments of the present invention is as follows. Starting from Figure 3 As can be seen, the normal area where the edge part of the fresh egg is relatively close to the stain feature is misidentified as a stain, and the accuracy of the final obtained fresh egg stain detection result is relatively low.

[0045] When dynamically adjusting the window size of pixel points, the window size can be determined according to the possibility that the pixel point is at the edge of the stain area. On the grayscale image of the fresh egg, the gradient direction of the eggshell edge is usually regular and orderly, while the gradient direction of the stain area is complex and disorderly. Therefore, the embodiments of the present invention can distinguish the two by obtaining the gradient direction entropy of each pixel point in the initial window of the current pixel point, so as to accurately obtain the stain area in the grayscale image of the fresh egg, that is, perform the following steps.

[0046] S2: Obtain the gradient direction angle of each pixel point in the grayscale image of the fresh egg, divide the gradient direction angle into multiple intervals, and determine the gradient direction entropy of the pixel point according to the entropy sum of the number of pixel points located in each interval in the initial window of the pixel point.

[0047] Among them, the size of the initial window can be set to 15, and the specific size of the initial window can be set to an odd number according to actual needs.

[0048] Specifically, when obtaining the pixel points in the initial window of the current pixel point, the current pixel point can be used as the center, and a plurality of pixel points can be evenly obtained around it to construct its initial window. The form of the initial window is a rectangle, and finally (15×15 - 1) pixel points around the current pixel point and the current pixel point are jointly used as the initial window of the current pixel point.

[0049] It can be understood that the normal eggshell surface usually has a relatively uniform texture structure, while the shape and texture of the stain are often irregular and complex, which may destroy the regularity of the eggshell surface. The gradient direction angle of the pixel point in the image can reflect the direction of the gray change at that point. In the window of the normal eggshell, the gradient direction angles are concentrated in a few intervals, and the gradient direction angles of the stain area are distributed in more intervals.

[0050] Based on this, the embodiments of the present invention can obtain the number of pixel points located in each gradient direction angle interval in the initial window of the current pixel point, so as to accurately obtain the gradient direction entropy of the current pixel point to distinguish the area where the current pixel point is located.

[0051] Exemplarily, in the embodiments of the present invention, the gradient direction angle is divided into multiple intervals, including: according to the preset number of intervals The gradient direction angle is divided into intervals.

[0052] Among them, It can be set to 16; the number of intervals can be specifically set according to actual needs, and the embodiments of the present invention do not limit this too much here.

[0053] Specifically, the range of the gradient direction angle of the pixel points in the image is usually from 0° to 180°. According to the preset number of intervals, it can be divided into 16 intervals, and the width of each interval is 11.25°. Among them, the first interval is [0°, 11.25°), the second interval is [11.25°, 22.5°), and the last interval is [168.75, 180°]. The last interval is closed on the left and right, and the other intervals are closed on the left and open on the right. By analogy, all intervals can be obtained, and the embodiments of the present invention will not elaborate here.

[0054] After obtaining the range of each interval of the gradient direction angle of the pixel points based on the above steps, the number of pixel points corresponding to the gradient direction angles in each interval in the initial window of the pixel points can be counted, so that the gradient direction entropy of the current pixel point can be determined according to the entropy sum of the number of pixel points in each interval in the initial window of the current pixel point.

[0055] Exemplarily, in the embodiments of the present invention, to calculate the gradient direction entropy of the pixel points, the following relational expression can be specifically referred to:

[0056] ;

[0057] is the gradient direction entropy of the pixel point, is the number of intervals of the gradient direction angle, is the number of pixel points in the initial window of the pixel point located in the th interval, is the logarithmic function with base e, is the linear normalization function.

[0058] In the above formula, the smaller the gradient direction entropy of the th pixel point, it indicates that the distribution of the gradient direction angles of the pixel points in the th pixel point window is more concentrated, and it is more likely to be a continuous area such as the eggshell edge; on the contrary, the smaller this value is, it indicates that the distribution of the gradient direction angles of the pixel points in the th pixel point window is more discrete, and it is more likely to be a stain edge area.

[0059] By analyzing the distribution of the gradient direction angles of the pixels in the initial window of each pixel according to the above steps, the gradient direction entropy of each pixel can be accurately obtained, thereby evaluating the possibility that each pixel is at the edge of the eggshell or the edge of the stain area. However, the edge also has a continuous feature. Only obtaining the gradient direction entropy of the pixels does not take into account the coherence of the pixel gradient distribution. In the grayscale image of a fresh egg, the gradient arrangement direction of the gray values at the eggshell edge is more continuous than that in the stain area. Therefore, when evaluating the possibility that each pixel is at the edge of the eggshell or the edge of the stain area, it is also necessary to obtain the geometric direction consistency in the initial window of the pixels in the grayscale image of the fresh egg, so as to accurately obtain the window size required for each pixel, that is, continue to execute the following steps.

[0060] S3: Calculate the local geometric direction consistency of the pixel according to the sum of the horizontal components and the sum of the vertical components of the gradient direction angles of all pixels in the initial window of the pixel.

[0061] It should be noted that the gradient direction angle of each pixel can correspond to a unit vector, whose horizontal component is the cosine function value and the vertical component is the sine function value. In the grayscale image of a fresh egg, the gradient arrangement direction of the gray values at the eggshell edge is more continuous than that in the stain area. When analyzing the local geometric direction consistency of the pixels, the overall direction vector of the area can be obtained by vectorially adding the vectors of the gradient direction angles of the pixels in the current pixel window, so as to analyze the vector consistency of the gradient direction angles of the pixels in the current pixel window. If the gradient directions in the window are highly consistent, it indicates that the direction coherence of the pixels in the window is strong; otherwise, if the gradient directions in the window are relatively disordered, it indicates that the pixel directions lack coherence.

[0062] In order to enhance the contribution of the pixels with better coherence when determining the window size, the texture significance of the eggshell edge pixels can be characterized by the gradient amplitude. When calculating the local geometric direction consistency, a higher weight is given to the more significant texture direction, so that more attention can be paid to the texture features that are discriminative for stain detection.

[0063] Exemplarily, in the embodiment of the present invention, the method for obtaining the horizontal component and the vertical component of the gradient direction angle of the pixel includes: taking the cosine function value of the gradient direction angle of the pixel as the horizontal component of the pixel, and taking the sine function value of the gradient direction angle of the pixel as the vertical component of the pixel.

[0064] After obtaining the horizontal component and the vertical component of each pixel in the initial window of the current pixel based on the above method, the local geometric direction consistency of the current pixel can be calculated based on this.

[0065] Exemplarily, in the embodiment of the present invention, when calculating the local geometric direction consistency of the pixel, the following relational expression can be referred to:

[0066] ;

[0067] is the local geometric direction consistency of the pixel point, is the initial window size, is the th gradient magnitude of the th pixel point in the initial window of the pixel point, is the linear normalization function, is the th horizontal component of the gradient direction angle of the th pixel point in the initial window of the pixel point, is the cosine function, is the sine function.

[0068] In the above formula, is the cumulative sum of weighted horizontal components in the initial window of the pixel point, is the cumulative sum of weighted vertical components in the initial window of the pixel point. The larger the cumulative sum, the higher the vector consistency of the gradient direction angles of the pixel points weighted in the initial window, the stronger the coherence, and the higher the possibility of being the eggshell edge. Based on the above steps, the gradient direction entropy and local geometric direction consistency of each pixel point can be obtained respectively. By analyzing the degree of chaos of the gradient direction and the degree of consistency of the local geometry of the pixel points, the regular texture of the eggshell and the abnormal texture of the stain can be more accurately distinguished, avoiding misjudgment of a single feature, and thus the window size of each pixel point can be accurately obtained.

[0070] S4: Calculate the target window size of the pixel point, and calculate the segmentation threshold of the pixel point according to the gray mean value and gray standard deviation of all pixel points in the target window of the pixel point.

[0071] Exemplarily, in the embodiment of the present invention, to calculate the target window size of the pixel point, the following relational expression can be specifically referred to:

[0072] ;

[0073] is the target window size of the pixel point, is the initial window size, is the abscissa index of the pixel point, is the abscissa index of the pixel point in the initial window of the pixel point, is the ordinate index of the pixel point, is the ordinate index of the pixel point in the initial window of the pixel point, is the local geometric direction consistency of the pixel point, is the local geometric direction consistency of the pixel point in the initial window of the pixel point, is the gradient direction entropy of the pixel point, is the exponential function with base e.

[0074] In the above formula, is the continuous confidence of the eggshell edge of the pixel point. Due to the continuity of the eggshell edge, when the local geometric direction consistency of the pixel point in its window is high and the average distance of the pixel point is farther, it indicates that the higher the possibility that the pixel point is the edge of the stain, and the higher the possible degree of the non - continuous stain pixel point misjudged as the eggshell edge. At this time, a larger window needs to be set to avoid missing the detection of the stain.

[0075] The higher the local geometric direction consistency of the pixel point and the smaller its gradient direction entropy, the more it conforms to the characteristics of the eggshell edge, and the higher the possibility of being the eggshell edge. At this time, a smaller window needs to be set to avoid misidentifying the normal eggshell edge pixels as stains when detecting the stain area.

[0076] It can be understood that based on the above steps, the target window size of each pixel point can be obtained. However, the size of the obtained target window may be an even non - integer. When determining the pixel point segmentation threshold, the required window is an odd integer length. Therefore, before determining the segmentation threshold based on the target window size of the pixel point, the present invention embodiment can first round down the target window size of the pixel point to an odd integer to obtain the final window size of the pixel point, and construct its window based on the final window size of the pixel point, so as to accurately determine its segmentation threshold in the final window of the pixel point.

[0077] Exemplarily, when constructing the final window of the current pixel based on the final window size of the current pixel, the current pixel can be used as the center, and surrounding pixels can be evenly obtained around it to construct the final window of the pixel. The surrounding pixels and the current pixel together constitute the final window of the current pixel.

[0078] Among them, if the number of surrounding pixels of some current pixels is not enough to construct their final windows, the final windows of the current pixels are constructed with the actually obtained number of surrounding pixels.

[0079] An example of rounding down to an odd integer: if the target window size of a pixel is 4.8, the size of its final window is 3; if the target window size of a pixel is 3.2, the size of its final window is 3.

[0080] Exemplarily, in the embodiments of the present invention, to calculate the segmentation threshold of a pixel, the following relational expression can be specifically referred to:

[0081] ;

[0082] is the segmentation threshold of the pixel, is the average gray value of all pixels in the final window of the pixel, is the standard deviation of the gray values of all pixels in the final window of the pixel, is the sensitivity coefficient.

[0083] Among them, the sensitivity coefficient is a preset value used to adjust the sensitivity of the segmentation threshold to the standard deviation. The sensitivity coefficient can be set to 0.2, and can be specifically set according to actual needs.

[0084] After obtaining the segmentation threshold of each pixel based on the above steps, the pixels in the final window of each pixel can be judged according to the segmentation threshold of each pixel, so as to accurately obtain the stain pixels.

[0085] S5: Process the fresh egg gray image according to the segmentation threshold of the pixel to obtain the stain detection result of the fresh egg gray image.

[0086] Exemplarily, in the embodiments of the present invention, processing the fresh egg gray image according to the segmentation threshold of the pixel includes: if the number of pixels not higher than the segmentation threshold of the pixel in the final window of the pixel of the fresh egg gray image is greater than the number threshold, then the pixel is a stain pixel.

[0087] Among them, the number threshold can be set to 5, and the number threshold can be specifically set according to actual needs.

[0088] Specifically, the pixels in the final window of the current pixel that are higher than the segmentation threshold of the current pixel can be marked as 1, and the pixels that are not higher than the segmentation threshold of the current pixel can be marked as 0. The obtained binary image is used as the segmentation result of the final window. If the number of pixels marked as 0 in the final window of the current pixel is greater than the number threshold, it indicates that the current pixel is a stain pixel.

[0089] It can be understood that if the number of pixels marked as 0 in the final window of the current pixel is not greater than the number threshold, it indicates that the current pixel is not in the stain area.

[0090] After obtaining all the stain pixels in the fresh egg grayscale image, the stain area can be obtained based on the stain pixels.

[0091] Exemplarily, in the embodiment of the present invention, processing the fresh egg grayscale image according to the segmentation threshold of the pixel to obtain the stain detection result of the fresh egg grayscale image includes: obtaining all the stain pixels in the fresh egg grayscale image, and taking the connected domain of the stain pixels as the stain in the fresh egg grayscale image.

[0092] Specifically, refer to Figure 4 as shown in Figure 4 which is a schematic diagram of the stain detection result of the fresh egg grayscale image obtained after dynamically adjusting the window size provided by the embodiment of the present invention. Combining Figure 3 and Figure 4 it can be seen that after dynamically adjusting the window size of the pixel, it is possible to effectively avoid misidentifying the eggshell edge as the stain area, accurately obtain the true stain area, thereby improving the accuracy of the stain detection on the surface of the fresh egg. If there is a stain on the surface of the fresh egg, it indicates that the surface may be contaminated and needs to be processed in time.

[0093] Exemplarily, in the embodiment of the present invention, after obtaining the stain detection result of the fresh egg grayscale image, it further includes: sending a cleaning prompt for the fresh egg corresponding to the fresh egg grayscale image with stains.

[0094] Among them, the prompt method can be a sound prompt for the coordinates where the fresh egg with stains is located, or using light beams of different colors to irradiate the fresh egg with stains, etc. The prompt method can be specifically set according to actual needs, and the embodiment of the present invention does not limit it too much here.

[0095] It can be seen that in the embodiment of the present invention, when obtaining the fresh egg stain detection result, the gradient direction angle of each pixel in the fresh egg grayscale image can be obtained, and the gradient direction angle is divided into multiple intervals. According to the sum of the entropy values of the number of pixels in each interval in the initial window of the pixel, the gradient direction entropy of the pixel is determined; according to the sum of the horizontal components and the sum of the vertical components of the gradient direction angles of all the pixels in the initial window of the pixel, the local geometric direction consistency of the pixel is calculated; calculate the The target window size of the pixel :

[0096] ;

[0097] is the initial window size, 、 are respectively the abscissa indexes of the th pixel and the th pixel in its initial window, 、 are respectively the ordinate indexes of the th pixel and the th pixel in its initial window, 、 are respectively the local geometric direction consistency degrees of the th pixel and the th pixel in its initial window, is the th pixel gradient direction entropy, is the exponential function with base e; calculate the segmentation threshold of the pixel according to the grayscale mean and grayscale standard deviation of all pixels in the pixel target window, and process the fresh egg grayscale image according to the segmentation threshold of the pixel to obtain the fresh egg grayscale image stain detection result, effectively improving the accuracy of the fresh egg stain detection result.

[0098] The above are only the preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent replacements, improvements, etc. made within the principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A stain detection method for fresh egg cleaning, characterized in that, Including: Obtain the gradient direction angles of each pixel point in the grayscale image of the fresh egg, divide the gradient direction angles into multiple intervals, and determine the gradient direction entropy of the pixel point according to the sum of the entropy values of the number of pixel points in each interval in the initial window of the pixel point; Calculate the local geometric direction consistency of the pixel point according to the sum of the horizontal components and the sum of the vertical components of the gradient direction angles of all pixel points in the initial window of the pixel point, including: ; is the local geometric direction consistency of the pixel point, is the initial window size, , are respectively the gradient magnitude and gradient direction angle of the pixel point in the initial window of the pixel point, , are respectively the horizontal component and vertical component of the gradient direction angle of the pixel point in the initial window of the Calculate the target window size of the pixel point : ; , are respectively the abscissa index of the pixel point and the pixel point in its initial window, , are respectively the ordinate index of the pixel point and the pixel point in its initial window, is the local geometric direction consistency of the pixel point in the initial window of the is the gradient direction entropy of the pixel point, is the exponential function with base e; calculate the segmentation threshold of the pixel point according to the gray mean and gray standard deviation of all pixel points in the target window of the pixel point, and process the fresh egg gray image according to the segmentation threshold of the pixel point to obtain the stain detection result of the fresh egg gray image.

2. The stain detection method for fresh egg cleaning according to claim 1, characterized in that, Before the step of obtaining the gradient direction angles of each pixel point in the grayscale image of the fresh egg, it further includes: Take a photo of the surface of the fresh egg for preprocessing to obtain a grayscale image of the fresh egg; wherein the preprocessing includes at least image denoising and grayscale processing.

3. A stain detection method for fresh egg cleaning according to claim 1, characterized in that, Dividing the gradient direction angles into multiple intervals, including: According to the preset number of intervals divide the gradient direction angle into intervals.

4. A stain detection method for fresh egg cleaning according to claim 1, characterized in that, The step of determining the gradient direction entropy of the pixel point according to the sum of the entropy values of the number of pixel points in each interval in the initial window of the pixel point, including: ; is the gradient direction entropy of the pixel point, is the number of intervals of the gradient direction angle, is the number of pixel points in the initial window of the pixel point that are located in the th interval, is the logarithmic function with base e, is the linear normalization function.

5. A stain detection method for fresh egg cleaning according to claim 1, characterized in that, The obtaining methods of the horizontal component and the vertical component of the gradient direction angle of the pixel point, including: Taking the cosine function value of the gradient direction angle of the pixel point as the horizontal component of the pixel point, and taking the sine function value of the gradient direction angle of the pixel point as the vertical component of the pixel point.

6. The stain detection method for fresh egg cleaning according to claim 1, wherein The step of calculating the segmentation threshold of the pixel point according to the grayscale mean value and the grayscale standard deviation of all pixel points in the target window of the pixel point, including: Rounding down the size of the target window of the pixel point to an odd integer to obtain the final window size of the pixel point; ; is the segmentation threshold for the pixel point, , are respectively the gray mean value and gray standard deviation of all pixel points in the final window of the pixel point, and is the sensitivity coefficient.

7. A stain detection method for fresh egg cleaning according to claim 1, characterized in that, Processing the grayscale image of the fresh egg according to the segmentation threshold of the pixel point, including: If the number of pixel points not higher than the segmentation threshold of the pixel point in the final window of the pixel point in the grayscale image of the fresh egg is greater than the number threshold, then the pixel point is a stain pixel point.

8. A stain detection method for fresh egg cleaning according to claim 7, characterized in that, Processing the grayscale image of the fresh egg according to the segmentation threshold of the pixel point to obtain the stain detection result of the grayscale image of the fresh egg, including: Obtain all stain pixel points in the grayscale image of the fresh egg, and take the connected domain of the stain pixel points as the stain in the grayscale image of the fresh egg.

9. A stain detection method for fresh egg cleaning according to claim 1, characterized in that After obtaining the stain detection result of the grayscale image of the fresh egg, it further includes: Send a cleaning prompt for the fresh egg corresponding to the grayscale image of the fresh egg with stains.

Citation Information

Patent Citations

  • Lung X-ray image processing method for lung fiber inhalation pathopoiesis

    CN118196123A

  • Intelligent control method and system of egg liquid spraying machine

    CN119600533A