Cooked rice grain shape detection method

The problem of accuracy in measuring the shape of cooked rice grains was solved by using the equivalent ellipse method. By utilizing label recognition and image processing technology, high-precision detection of irregular rice grains was achieved, which is applicable to ordinary equipment.

CN121120753APending Publication Date: 2025-12-12SICHUAN AGRI UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511283818.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-09-09
Publication Date
2025-12-12

AI Technical Summary

Technical Problem

Existing technologies cannot accurately measure morphological data such as grain length, grain width, and extensibility of cooked rice grains, especially for uneven, serrated, or curved cooked rice grains.

Method used

The equivalent ellipse method is adopted. By using label recognition and image processing technology, the ratio of the geometric information of the label is calculated to obtain the scale. Gaussian blur and polygon fitting are performed. The area and perimeter of the fitted polygon are used to calculate the major and minor axes of the equivalent ellipse. The correction is made in combination with the classification of rice varieties, and finally the rice grain morphology detection is realized.

Benefits of technology

It achieves high-precision morphological measurement of irregular cooked rice grains, reduces errors caused by differences in photographic height, is suitable for ordinary computers and mobile phones, and is inexpensive.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121120753A_ABST
    Figure CN121120753A_ABST
Patent Text Reader

Abstract

The invention discloses a cooked rice grain shape detection method. The method comprises the following steps: acquiring an image containing a label and cooked rice grains to be detected, and preprocessing the image; obtaining a proportional scale; detecting the contour of the cooked rice grains to be detected in the preprocessed image, calculating the area, and recording the area as an initial area; smooth processing and polygon fitting are carried out on the contour of the created mask through Gaussian blur; calculating the area and the perimeter of the fitting polygon, and calculating the long axis and the short axis of the equivalent ellipse based on the scale and the area and the perimeter of the fitting polygon; and correcting the long axis of the equivalent ellipse. Starting from the morphological characteristics of cooked rice grains, an equivalent ellipse method is used for replacing a traditional minimum enclosing rectangle method, the limitation of a fitting function on traditional computer vision detection of the rice grain morphology is avoided, a tag identification function is added, the sampling height is allowed to change randomly, errors caused by different photographing heights are reduced, and the accuracy of the detection result is improved. Accurate measurement of geometric data of irregular rice is realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of rice grain quality testing, specifically to a method for detecting the morphology of cooked rice grains. Background Technology

[0002] Rice is an important food crop, and in recent years, with the continuous improvement of living standards, consumers have increasingly higher requirements for rice quality. The morphological measurement of cooked rice grains is a crucial part of rice quality assessment. This measurement mainly includes grain length, grain width, and extensibility. Although most rice grains are oval in shape, their shape changes significantly after high-temperature cooking. The changes in grain shape after cooking are an important indicator of rice quality. However, because the boundaries of cooked rice grains are no longer smooth ovals or oblongs, but rather uneven and serrated, with some varieties exhibiting extreme curvature, accurately measuring the morphology of individual rice grains becomes extremely difficult.

[0003] Currently, there are only methods for detecting the morphology of polished rice available on the market, but a lack of methods applicable to the detection of cooked rice grains with complex shapes. Traditional rice grain morphology detection involves binarizing the rice grains in an image, identifying their contours, and directly measuring the morphological data of the rice grains using the minimum bounding rectangle. This method is simple and easy to implement, but it cannot accurately measure the morphological data such as the length, width, and extensibility of curved cooked rice grains. Summary of the Invention

[0004] To address the aforementioned shortcomings in the existing technology, the present invention provides a method for detecting the morphology of cooked rice grains, which solves the problem that the existing technology cannot accurately measure the length and width of cooked rice grains.

[0005] To achieve the above-mentioned objectives, the technical solution adopted by this invention is as follows: A method for detecting the morphology of cooked rice grains is provided, comprising the following steps: Acquire images containing labels and cooked rice grains to be detected; the labels are regular shapes, and the size of the labels exceeds the area of ​​the cooked rice grains to be detected; The acquired images are preprocessed to obtain preprocessed images; The scale of the preprocessed image is obtained by calculating the ratio of the pixels occupied by the label geometric information to the actual geometric information; the outline of the cooked rice grain to be detected in the preprocessed image is detected and the area is calculated and recorded as the initial area; A mask is created for the contours whose initial area is within the threshold range. The contours of the masked contours are then smoothed and fitted with polygons using Gaussian blur to obtain the fitted polygons. Calculate the area and perimeter of the fitted polygon, and calculate the major and minor axes of the equivalent ellipse based on the scale and the area and perimeter of the fitted polygon; where twice the length of the major axis is the grain length, and twice the length of the minor axis corresponds to the grain width. Rice grains are classified according to the ratio of grain length to grain width. The major axis of the equivalent ellipse corresponding to different rice grain varieties is corrected. The minor axis of the equivalent ellipse and the major axis of the corrected equivalent ellipse are used as the final detection results to complete the morphology detection of cooked rice grains.

[0006] Furthermore, specific methods for acquiring images containing labels and cooked rice grains to be detected include: The cooked rice grains to be tested are placed on a contrasting background object, and a label is placed next to the cooked rice grains to be tested. An image containing the label and the cooked rice grains to be tested is acquired using an image acquisition device. During the acquisition process, the image acquisition device is kept parallel to the plane on which the cooked rice grains to be tested are located.

[0007] Furthermore, specific methods for preprocessing the acquired images include: The acquired image is converted to grayscale to obtain a grayscale image; In a grayscale image, regions with pixel values ​​greater than or equal to 125 are converted to white, and regions with pixel values ​​less than 125 are converted to black, resulting in a binarized image. Median filtering is applied to the binarized image to obtain a denoised image, i.e., the preprocessed image.

[0008] Furthermore, the expression for grayscale conversion is: gray = 0.114 * B + 0.587 * G + 0.299 * R Where gray represents the pixel value of a single pixel after grayscale conversion; B, G, and R represent the pixel values ​​of the blue, green, and red channels of a single pixel in the acquired image, respectively.

[0009] Furthermore, specific methods for obtaining the scale of the preprocessed image by calculating the ratio of pixels occupied by label geometric information to actual geometric information include: The labels in the preprocessed image are obtained, and the geometric information of the labels is extracted using the boundingRect function in OpenCV. The ratio of the pixels occupied by the label geometric information to the actual geometric information is calculated to obtain the scale of the preprocessed image; where the length of the geometric information is in millimeters.

[0010] Furthermore, when an image containing both the label and the cooked rice grain to be detected contains only the label and the cooked rice grain to be detected, the contour with the largest area among all contours is taken as the contour of the label; if the label is rectangular, the geometric information is the length and width of the rectangle; if the label is circular, the geometric information is the diameter.

[0011] Furthermore, specific methods for smoothing the contours of the created mask and fitting polygons using Gaussian blur include: The Gaussian blur function is used to smooth and eliminate noise in the contour of the mask to reduce the number of vertices required for polygon fitting, resulting in the Gaussian blurred contour; the kernel size used by the Gaussian blur function is 9×9. The Canny edge detection algorithm is used to detect the contour boundary after Gaussian blurring in order to avoid interference from the surface texture of cooked rice grains, and the contour after the boundary is calibrated is obtained; the high and low thresholds of the parameters in the Canny edge detection algorithm are set to 150 and 50, respectively. The contour after calibration boundary is fitted with polygons by using the simplified curve or polyline algorithm Douglas-Peucker to obtain the fitted polygon.

[0012] Furthermore, when performing polygon fitting on the contour after calibration boundary using the Douglas-Peucker polyline algorithm, the approximate accuracy is determined by perimeter calculation, and the approximate accuracy multiplied by the contour perimeter is used as the constraint threshold for polygon fitting in the Douglas-Peucker algorithm.

[0013] Furthermore, the specific methods for calculating the area and perimeter of the fitted polygon, and for calculating the major and minor axes of the equivalent ellipse based on the scale and the area and perimeter of the fitted polygon, include: The perimeter and area of ​​the fitted polygon are extracted by calling the perimeter and area calculation functions arcLength and contourArea in OpenCV, and then converted into the actual perimeter and actual area according to the scale. Establish the formula for the area of ​​an ellipse; use Ramanujan's first approximation formula as the formula for the ellipse's perimeter. Based on the actual perimeter and actual area, the system of equations consisting of the area formula and the perimeter formula of the ellipse is solved using the fsolve tool in the SciPy library of Python, thus obtaining the major axis and minor axis of the equivalent ellipse.

[0014] Furthermore, based on the ratio of grain length to grain width, rice grain varieties are classified, and specific methods for correcting the major axis of the equivalent ellipse corresponding to different rice grain varieties include: Varieties with a grain length to grain width ratio greater than 2.65 are considered indica rice, while those with a ratio less than or equal to 2.65 are considered japonica rice. The major axis of the equivalent ellipse corresponding to indica rice is reduced by 1.44 mm to obtain the major axis of the corrected equivalent ellipse for indica rice. The major axis of japonica rice is reduced by 1.07 mm to obtain the major axis of the corrected equivalent ellipse for japonica rice.

[0015] The beneficial effects of this invention are as follows: 1. This invention starts from the morphological characteristics of cooked rice grains and uses the equivalent ellipse method to replace the traditional minimum bounding rectangle method, bypassing the limitation of the fitting function on the traditional computer vision detection of rice grain morphology. The addition of label recognition function allows random variation of sampling height, reduces the error caused by different shooting heights, and realizes accurate measurement of irregular rice geometric data.

[0016] 2. This invention achieves high-precision detection of cooked rice grain morphology at low cost and can be applied to ordinary computers and mobile phones. Attached Figure Description

[0017] Figure 1 This is a flowchart illustrating the method. Figure 2 An image containing a label and cooked rice grains to be detected, with a black background; Figure 3 This is a schematic diagram showing that the grain length of indica rice obtained by the equivalent ellipse method in the embodiment is larger than the expected value. Figure 4 This is a schematic diagram showing that the grain length of japonica rice obtained by the equivalent ellipse method in the embodiment is larger than the expected value. Detailed Implementation

[0018] The specific embodiments of the present invention are described below to enable those skilled in the art to understand the present invention. However, it should be understood that the present invention is not limited to the scope of the specific embodiments. For those skilled in the art, various changes are obvious as long as they are within the spirit and scope of the present invention as defined and determined by the appended claims. All inventions utilizing the concept of the present invention are protected.

[0019] like Figure 1 As shown, the method for detecting the morphology of cooked rice grains includes the following steps: S1. Acquire an image containing a label and cooked rice grains to be detected; wherein the label is a regular shape and the size of the label exceeds the area of ​​the cooked rice grains to be detected; S2. Preprocess the acquired images to obtain preprocessed images; S3. Obtain the scale of the preprocessed image by calculating the ratio of the pixels occupied by the label geometric information to the actual geometric information; detect the outline of the cooked rice grains to be detected in the preprocessed image and calculate the area, which is recorded as the initial area; S4. Create a mask for the contour with an initial area within the threshold range, and smooth the contour of the mask by Gaussian blur and perform polygon fitting to obtain the fitted polygon. S5. Calculate the area and perimeter of the fitted polygon, and calculate the major and minor axes of the equivalent ellipse based on the scale and the area and perimeter of the fitted polygon; where twice the length of the major axis is the grain length, and twice the length of the minor axis corresponds to the grain width. S6. Based on the ratio of grain length to grain width, classify rice grain varieties, correct the major axis of the equivalent ellipse corresponding to different rice grain varieties, and use the minor axis of the equivalent ellipse and the corrected major axis of the equivalent ellipse as the final detection result to complete the morphology detection of cooked rice grains.

[0020] In step S1, the specific method for acquiring an image containing the label and the cooked rice grains to be detected includes: Place the cooked rice grains to be tested on a contrasting background object (preferably black), and place a label next to the grains. Capture an image containing both the label and the cooked rice grains using an image acquisition device (mobile phone, camera, etc.). Figure 2 As shown ( Figure 2 (The white rectangle in the image represents the label). During the acquisition process, the image acquisition device is kept parallel to the plane containing the cooked rice grains to be detected, in order to ensure image clarity and that the image contains only the rice grains and the label.

[0021] In step S2, the specific methods for preprocessing the acquired images include: S2-1. Convert the acquired image to grayscale to obtain a grayscale image; S2-2. Convert the regions with pixel values ​​greater than or equal to 125 in the grayscale image to white, and convert the regions with pixel values ​​less than 125 to black to obtain a binarized image. S2-3. Perform median filtering on the binarized image to obtain a denoised image, i.e., the preprocessed image.

[0022] In this embodiment, the expression for grayscale is: gray = 0.114 * B + 0.587 * G + 0.299 * R Where gray represents the pixel value of a single pixel after grayscale conversion; B, G, and R represent the pixel values ​​of the blue, green, and red channels of a single pixel in the acquired image, respectively.

[0023] The principle of median filtering is to use the median value of all pixels within a rectangular window centered on the noise point as the median value of that point.

[0024] In step S3, the specific method for obtaining the scale of the preprocessed image by calculating the ratio of the pixels occupied by the label geometric information to the actual geometric information includes: S3-1. Obtain the labels in the preprocessed image, use the boundingRect function in OpenCV to extract the geometric information of the labels, and calculate the ratio of the pixels occupied by the label geometric information to the actual geometric information to obtain the scale of the preprocessed image; where the length of the geometric information is in millimeters.

[0025] S3-2. When an image containing a label and cooked rice grains to be detected contains only the label and cooked rice grains to be detected, the outline with the largest area among all outlines is taken as the outline of the label; if the label is a rectangle, the geometric information is the length and width of the rectangle; if the label is a circle, the geometric information is the diameter.

[0026] In step S4, the specific methods for smoothing the contour of the mask creation using Gaussian blur and fitting polygons include: S4-1. Use the Gaussian Blur function to smooth and eliminate noise in the contour of the mask to reduce the number of vertices required for polygon fitting, and obtain the Gaussian blurred contour so that the subsequent fitting results are more in line with the actual shape; the kernel size used by the Gaussian Blur function is 9×9. S4-2. Use the Canny edge detection algorithm to detect the contour boundary after Gaussian blurring to avoid interference from the surface texture of cooked rice grains, and obtain the contour after the boundary is calibrated; wherein the high and low thresholds of the parameters in the Canny edge detection algorithm are set to 150 and 50 respectively. S4-3. Use the simplified curve or polyline algorithm Douglas-Peucker to perform polygon fitting on the contour after calibration boundary to obtain the fitted polygon.

[0027] In this embodiment, when performing polygon fitting on the contour after calibration boundary using the Douglas-Peucker polyline algorithm, the approximate accuracy is determined by perimeter calculation. The approximate accuracy multiplied by the contour perimeter is used as the constraint threshold for polygon fitting in the Douglas-Peucker algorithm. Optionally, the approximate accuracy is 0.01, meaning that the difference between the fitted polygon and the original contour perimeter does not exceed 1% of the original contour perimeter.

[0028] In step S5, the area and perimeter of the fitted polygon are calculated. The specific method for calculating the major and minor axes of the equivalent ellipse based on the scale and the area and perimeter of the fitted polygon includes: S5-1. Use OpenCV to call the perimeter and area calculation functions arcLength and contourArea to extract the perimeter and area of ​​the fitted polygon, and convert them into the actual perimeter and actual area according to the scale. S5-2. Establish the formula for the area of ​​an ellipse; use Ramanujan's first approximation formula as the formula for the circumference of the ellipse. S5-3. Based on the actual perimeter and actual area, use the nonlinear equation solving tool fsolve in Python's SciPy library to solve the system of equations consisting of the area formula and the perimeter formula of the ellipse, thus obtaining the major axis and minor axis of the equivalent ellipse.

[0029] In practice, cooked rice grains may be curved, making it difficult to measure their length and width. This embodiment uses an equivalent ellipse method, which can represent both normal and curved rice grains as ellipses. Using the measured perimeter and area of ​​the polygon, we can establish two equations. The formula for the area of ​​an ellipse is: ,in Pi The length of the major axis of the ellipse Let be the length of the minor axis of the ellipse. Ramanujan's first approximation formula, used as the formula for the circumference of the ellipse, is: fsolve integrates the Powell algorithm, the Levenberg-Marquardt algorithm, and the MINAPK algorithm to achieve accurate calculation of the major and minor axes of an ellipse. When using this method to solve for the geometric information of an ellipse, it is necessary to set initial values ​​for the major and minor axes. This embodiment assumes... The initial value can be obtained using the area formula. , The final measured length of the cooked rice grains was [missing value]. Particle width is Based on the above equivalent ellipse method, the morphological data of the rice grains are finally obtained, including grain length, grain width, perimeter, and area.

[0030] In this embodiment, 10 indica rice varieties and 10 japonica rice varieties were randomly selected, with 10 grains from each variety. The grain length and width (expected values) were manually measured and compared with the grain length and width calculated using the equivalent ellipse method to analyze the error. The results showed that the grain length obtained using the equivalent ellipse method was larger than the expected value, but the trend was generally consistent, and the degree of overestimation differed between indica and japonica rice. Figure 3 and Figure 4 As shown. Linear regression was used to fit the expected and calculated values ​​to obtain the conversion relationship between the calculated and expected values. Different numerical corrections were applied to indica and japonica rice respectively. The ratio of grain length to grain width was defined as the index to distinguish between indica and japonica rice. By statistically analyzing the grain length and grain width data of the above 10 indica and 10 japonica rice varieties, a threshold of 2.65 for the grain length / grain width ratio was set. Varieties with a ratio greater than 2.65 were considered indica rice, and those less than or equal to 2.65 were considered japonica rice. The grain length correction value for indica rice varieties was 1.44 mm (grain length obtained by the equivalent ellipse method minus this correction value), and the correction value for japonica rice was 1.07 mm (grain length obtained by the equivalent ellipse method minus this correction value). Finally, the corrected grain shape data were used as the measurement data.

[0031] In summary, this invention, starting from the morphological characteristics of cooked rice grains, uses the equivalent ellipse method instead of the traditional minimum bounding rectangle method, bypassing the limitations of the fitting function on the traditional computer vision detection of rice grain morphology. The addition of label recognition function allows for random variations in sampling height, reducing errors caused by different shooting heights, and achieving accurate measurement of irregular rice geometric data.

Claims

1. A method for detecting the morphology of cooked rice grains, characterized in that, Includes the following steps: Acquire images containing labels and cooked rice grains to be detected; the labels are regular shapes, and the size of the labels exceeds the area of ​​the cooked rice grains to be detected; The acquired images are preprocessed to obtain preprocessed images; The scale of the preprocessed image is obtained by calculating the ratio of the pixels occupied by the label's geometric information to the actual geometric information. The outline of the cooked rice grain to be detected in the preprocessed image is detected and its area is calculated and recorded as the initial area. A mask is created for the contours whose initial area is within the threshold range. The contours of the masked contours are then smoothed and fitted with polygons using Gaussian blur to obtain the fitted polygons. Calculate the area and perimeter of the fitted polygon, and calculate the major and minor axes of the equivalent ellipse based on the scale and the area and perimeter of the fitted polygon; where twice the length of the major axis is the grain length, and twice the length of the minor axis corresponds to the grain width. Rice grains are classified according to the ratio of grain length to grain width. The major axis of the equivalent ellipse corresponding to different rice grain varieties is corrected. The minor axis of the equivalent ellipse and the major axis of the corrected equivalent ellipse are used as the final detection results to complete the morphology detection of cooked rice grains.

2. The method for detecting the morphology of cooked rice grains according to claim 1, characterized in that, Specific methods for acquiring images containing labels and cooked rice grains to be detected include: The cooked rice grains to be tested are placed on a contrasting background object, and a label is placed next to the cooked rice grains to be tested. An image containing the label and the cooked rice grains to be tested is acquired using an image acquisition device. During the acquisition process, the image acquisition device is kept parallel to the plane on which the cooked rice grains to be tested are located.

3. The method for detecting the morphology of cooked rice grains according to claim 1, characterized in that, Specific methods for preprocessing the acquired images include: The acquired image is converted to grayscale to obtain a grayscale image; In a grayscale image, regions with pixel values ​​greater than or equal to 125 are converted to white, and regions with pixel values ​​less than 125 are converted to black, resulting in a binarized image. Median filtering is applied to the binarized image to obtain a denoised image, i.e., the preprocessed image.

4. The method for detecting the morphology of cooked rice grains according to claim 3, characterized in that, The expression for grayscale conversion is: gray = 0.114 * B + 0.587 * G + 0.299 * R Where gray represents the pixel value of a single pixel after grayscale conversion; B, G, and R represent the pixel values ​​of the blue, green, and red channels of a single pixel in the acquired image, respectively.

5. The method for detecting the morphology of cooked rice grains according to claim 1, characterized in that, Specific methods for obtaining the scale of a preprocessed image by calculating the ratio of pixels occupied by label geometric information to actual geometric information include: The labels in the preprocessed image are obtained, and the geometric information of the labels is extracted using the boundingRect function in OpenCV. The ratio of the pixels occupied by the label geometric information to the actual geometric information is calculated to obtain the scale of the preprocessed image; where the length of the geometric information is in millimeters.

6. The method for detecting the morphology of cooked rice grains according to claim 5, characterized in that, When an image containing both a label and the cooked rice grains to be detected contains only the label and the cooked rice grains to be detected, the outline with the largest area among all outlines is taken as the outline of the label; if the label is a rectangle, the geometric information is the length and width of the rectangle; if the label is a circle, the geometric information is the diameter.

7. The method for detecting the morphology of cooked rice grains according to claim 1, characterized in that, Specific methods for smoothing the contours of a mask using Gaussian blur and fitting polygons include: The Gaussian blur function is used to smooth and eliminate noise in the contour of the mask to reduce the number of vertices required for polygon fitting, resulting in the Gaussian blurred contour; the kernel size used by the Gaussian blur function is 9×9. The Canny edge detection algorithm is used to detect the contour boundary after Gaussian blurring in order to avoid interference from the surface texture of cooked rice grains, and the contour after the boundary is calibrated is obtained; the high and low thresholds of the parameters in the Canny edge detection algorithm are set to 150 and 50, respectively. The contour after calibration boundary is fitted with polygons by using the simplified curve or polyline algorithm Douglas-Peucker to obtain the fitted polygon.

8. The method for detecting the morphology of cooked rice grains according to claim 7, characterized in that, When performing polygon fitting on the contour after calibration using the Douglas-Peucker polyline algorithm, the approximate accuracy is determined by perimeter calculation. The approximate accuracy is multiplied by the contour perimeter as the constraint threshold for polygon fitting in the Douglas-Peucker algorithm.

9. The method for detecting the morphology of cooked rice grains according to claim 1, characterized in that, Specific methods for calculating the area and perimeter of the fitted polygon, and for calculating the major and minor axes of the equivalent ellipse based on the scale and the area and perimeter of the fitted polygon, include: The perimeter and area of ​​the fitted polygon are extracted by calling the perimeter and area calculation functions arcLength and contourArea in OpenCV, and then converted into the actual perimeter and actual area according to the scale. Establish the formula for the area of ​​an ellipse; use Ramanujan's first approximation formula as the formula for the ellipse's perimeter. Based on the actual perimeter and actual area, the system of equations consisting of the area formula and the perimeter formula of the ellipse is solved using the fsolve tool in the SciPy library of Python, thus obtaining the major axis and minor axis of the equivalent ellipse.

10. The method for detecting the morphology of cooked rice grains according to claim 1, characterized in that, Rice varieties are classified based on the ratio of grain length to grain width. Specific methods for correcting the major axis of the equivalent ellipse corresponding to different rice varieties include: Varieties with a grain length to grain width ratio greater than 2.65 are considered indica rice, while those with a ratio less than or equal to 2.65 are considered japonica rice. The major axis of the equivalent ellipse corresponding to indica rice is reduced by 1.44 mm to obtain the major axis of the corrected equivalent ellipse for indica rice. The major axis of japonica rice is reduced by 1.07 mm to obtain the major axis of the corrected equivalent ellipse for japonica rice.