An Algorithm for Detecting and Segmenting Concave Points of Adhesive Grains
By detecting the concave points in the adhesion grain image and performing elliptical fitting segmentation, the problem of unstable adhesion grain segmentation is solved, and high-precision and low-cost adhesion grain segmentation is achieved.
Patent Information
- Application Number
- CN202210825600.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-14
- Publication Date
- 2025-07-22
- Estimated Expiration
- 2042-07-14
AI Technical Summary
The existing adhesion grain segmentation algorithm is prone to over-segment or under-segment, and the segmentation effect is unstable, so it is impossible to achieve high-precision segmentation without manual intervention between adhesion grains.
A concave point detection and segmentation algorithm for adhesion grains is adopted. By collecting color grain images under normal light, the grains are allowed to adhere to each other and convert them into binary images, the area of the connected area is counted, the small area is deleted, and the grains are divided into single and multiple grain areas, the concave points are extracted and elliptical fitting is performed.
It realizes high-precision segmentation of adhesion grains under ordinary lighting and mobile phone shooting conditions, without special equipment and manual intervention, reducing operating costs and improving segmentation accuracy and efficiency.
Smart Images

Figure CN115330686B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of agricultural production, and particularly to an algorithm for detecting and segmenting concave points of adhered grains. Background Art
[0002] In the research of the agricultural field, it is often necessary to segment the images of adhered grains to further detect the morphological parameters such as the length and width of the grains. The traditional method is to manually measure the morphological parameters of the grains. This method is not only time-consuming and laborious, but also difficult to guarantee the accuracy, and cannot meet the requirements of rapid and accurate measurement.
[0003] Currently, digital image processing technology is used to automatically segment grain targets, and then measure the morphological parameters of each grain, thereby saving a large amount of manpower. To ensure accurate segmentation of grains, it is generally required that there is a certain space between grains when placing them, and they cannot adhere to each other. In actual operation, this will bring two problems. One is that since it is required to place the grains separately, this will increase the manpower requirement. The other is that since the number of grains in an image is small, when statistically analyzing the morphological parameters of a large number of grains, a large number of grain images need to be taken, which also increases the manpower. Therefore, when placing grains, it is hoped that grains can adhere to each other, which poses higher requirements for the grain segmentation algorithm.
[0004] The currently common segmentation algorithms for adhered targets mainly include the segmentation algorithm based on watershed, the concave point pair matching segmentation algorithm, etc. The segmentation algorithm based on watershed can complete the segmentation of grains, but when the image contains noise or the target has a rough edge, this method is prone to over-segmentation, and when there is relatively serious adhesion between grains, this method is prone to under-segmentation. In addition, the concave point pair matching segmentation algorithm first needs to extract the connected target region, then detect the concave points on the contour line of the target region, and then form a segmentation line through the matching of concave point pairs, and finally segment the adhered target region. This method has more constraints on the adhered grain region, and the segmentation effect is unstable. Summary of the Invention
[0005] In view of the above-mentioned defects of the prior art, the technical problem to be solved by the present invention is that the existing adhesion segmentation methods are prone to over-segmentation or under-segmentation, or have more constraints on the adhered grain region and the segmentation effect is unstable. The present invention provides an algorithm for detecting and segmenting concave points of adhered grains, which does not require a professional camera environment and equipment, does not require manual intervention, is easy to operate, has a low cost, and has a high segmentation accuracy.
[0006] To achieve the above object, the present invention provides an algorithm for detecting and segmenting concave points of adhered grains, including the following steps:
[0007] Step 1: Under normal light, collect color grain images and allow the grains to adhere to each other;
[0008] Step 2: Convert the color grain image into a binary grain image;
[0009] Step 3: Count the area of each grain connected region in the binary grain image, and delete the connected regions with an area less than 100;
[0010] Step 4: Take the area of the smallest grain connected region in the area of the grain connected regions after deleting the connected regions with an area less than 100 as the area S0 of a single grain, and then calculate the perimeter L0 of a single grain according to S0;
[0011] Step 5: Divide the grain connected regions in the binary grain image into two categories. The first category of grain connected region Ω I refers to the grain connected region that contains only a single grain, and the second category of grain connected region Ω II refers to the grain connected region that contains two or more adhered grains;
[0012] Step 6: Extract the contour of the grain connected region belonging to Ω II ;
[0013] Step 7: Detect the concave points of the grain connected region belonging to Ω II ;
[0014] Step 8: Perform ellipse fitting on the curve segments on the grain connected region, and use the fitted ellipse to segment the first category of grain connected region Ω I , for the remaining grain connected regions, delete the connected regions with an area less than 100, and then return to Step 5 until all the first category of grain connected regions Ω I are segmented from the color grain image.
[0015] Furthermore, in Step 1, under normal light, collect the color grain image and allow adhesion between grains, which specifically includes the following steps:
[0016] Place the grains on a non-reflective black background cloth and allow adhesion between grains;
[0017] Under normal light, place the mobile phone directly above the grains to take a picture to obtain the color grain image.
[0018] Furthermore, in Step 2, convert the color grain image into a binary grain image, which specifically includes the following steps:
[0019] Add the red value, green value, and blue value of each pixel in the color grain image to obtain m. When m ≥ 200, regard this pixel as a grain and represent it with 1. Otherwise, when m < 200, regard this pixel as the background and represent it with 0, thereby converting the color grain image into a binary grain image.
[0020] Further, in step three, the areas of the connected regions of each grain in the binary grain image are counted, and the connected regions with an area less than 100 are deleted. The specific steps are as follows:
[0021] For the binary grain image obtained in step two, count the number of pixels contained in each connected region where the pixel value is equal to 1, and take the number of pixels as the area of the connected region;
[0022] Delete the connected regions with an area less than 100.
[0023] Further, in step four, take the area of the smallest grain connected region in the grain connected region areas after deleting the connected regions with an area less than 100 as the area S0 of a single grain, and then calculate the perimeter L0 of a single grain according to S0. The specific steps are as follows:
[0024] According to the areas of the grain connected regions obtained in step three, take the area of the smallest grain connected region in the grain connected region areas after deleting the connected regions with an area less than 100 as the area S0 of a single grain;
[0025] The shape of the grain can be regarded as an ellipse. For grains of a fixed variety, the ratio of the length a of the major semi-axis to the length b of the minor semi-axis of the corresponding ellipse is a fixed value η, that is, a = ηb; according to the ellipse area formula S0 = πab, we get b = , and further according to the ellipse perimeter formula L = 2πb + 4(a - b), we get the perimeter L0 of a single grain = [2π + 4(η - 1)] .
[0026] Further, in step five, divide the grain connected regions in the binary grain image into two categories. The first type of grain connected region Ω I refers to the grain connected region that only contains a single grain, and the second type of grain connected region Ω II refers to the grain connected region that contains two or more adhered grains. The specific steps are as follows:
[0027] According to the areas of the grain connected regions obtained in step three, when the area S of the grain connected region is < 1.2S0, then the grain connected region only contains a single grain, and this connected region is regarded as the first type of grain connected region Ω I ; when the area S of the grain connected region is ≥ 1.2S0, then the grain connected region contains two or more adhered grains, and this connected region is regarded as the second type of grain connected region Ω II .
[0028] Further, in step six, extract the contours of the grain connected regions belonging to Ω II . The specific steps are as follows:
[0029] (1) Take out a grain connected region ω from Ω II ; i ;
[0030] (2) Calculate the sum of the eight-neighborhoods of each point in the grain connected region, and take the points with the result less than or equal to 6 as candidate points;
[0031] (3) Mark the leftmost candidate point a as the contour point of the grain connected region, and take point a as the current point p0;
[0032] (4) With the current point p0 as the center, arbitrarily select a candidate point p1 in the eight-neighborhood of p0. If point p1 is not marked as a contour point, then mark point p1 as the contour point of the grain connected region, and take point p1 as the current point p0;
[0033] (5) Repeat step (4) until point a appears in the eight-neighborhood of the current point p0, then the contour extraction is completed.
[0034] Furthermore, in step seven, detect the concave points of the grain connected region belonging to Ω II , which specifically includes the following steps:
[0035] (1) Take out a grain connected region ω from Ω II ; i ;
[0036] (2) Traverse each contour point p i on ω obtained in step six. Taking p i as the reference point, take the 7th point p i forward along the contour, and then take the 7th point p i1 backward along the contour; i2 ;
[0037] (3) Construct a circle C with p i as the center and the distance |p i p i1 | between p i and p i1 as the radius, and take 360 points at equal angular intervals of 1° on the circle C;
[0038] (4) Calculate the point i1 on the circle C that is closest to p , and calculate the point i2 on the circle C that is closest to p ;
[0039] (5) and Divide the circle C into and two arcs, and count The number n1 of points on the circular arc with a value equal to 1 is then counted. The number n2 of points on the circular arc with a value equal to 1 is counted, and the larger of n1 and n2 is taken as the contour point p i of the angle;
[0040] (6) For each contour point p i on ω i with the angle θ i compare it with the angles θ i-1 of its previous and next contour points i+1 . When θ i > θ i-1 , and θ i > θ i+1 , and θ i > 220, then the contour point p i is taken as the concave point of the grain connected region to which p i belongs.
[0041] Furthermore, in step eight, the curve segments on the grain connected region are fitted with an ellipse, and the first type of grain connected region Ω I is segmented by the fitted ellipse. For the remaining grain connected regions, the connected regions with an area less than 100 are deleted, and then return to step five until all the first type of grain connected regions Ω I are segmented from the color grain image. The specific steps are as follows:
[0042] (1) The concave points on the grain connected region divide the region contour into several curve segments;
[0043] (2) The number of contour points of each curve segment is counted, and this number is taken as the length of the curve segment;
[0044] (3) For the curve segments with a length greater than 0.5L0, an ellipse fitting is performed, and the grain connected region is divided into two parts. One part of the grain connected region located inside the fitted ellipse is regarded as the first type of grain connected region Ω I , and for the remaining grain connected regions, the connected regions with an area less than 100 are deleted;
[0045] (4) Then return to step five until all the first type of grain connected regions Ω I are segmented from the color grain image.
[0046] Technical effects
[0047] The concave point detection and segmentation algorithm for adhering grains provided by the present invention only requires a black background cloth and a mobile phone to capture grain images under normal lighting conditions, without the need to prepare a special imaging environment and imaging equipment, which is easy to operate and has low cost. When capturing grain images, adhesion between grains is allowed, and there is no need to manually intervene in the placement of grains before shooting, reducing labor costs. Moreover, this method only needs to perform concave point detection and elliptical fitting segmentation on the grain connected regions with grain adhesion in the image, and the iterative segmentation method can be used to complete the segmentation operation of adhering grains. Finally, independent grains are obtained, solving the problem of segmenting adhering grains and improving the segmentation accuracy.
[0048] The following will further illustrate the concept, specific structure and technical effects of the present invention with reference to the accompanying drawings, so as to fully understand the purpose, features and effects of the present invention. Brief Description of the Drawings
[0049] Figure 1 It is a schematic flowchart of the concave point detection and segmentation algorithm for adhering grains in a preferred embodiment of the present invention;
[0050] Figure 2 It is a color grain image collected by the concave point detection and segmentation algorithm for adhering grains in a preferred embodiment of the present invention;
[0051] Figure 3 It is a binary grain image of the concave point detection and segmentation algorithm for adhering grains in a preferred embodiment of the present invention;
[0052] Figure 4 It is a binary grain image obtained after removing the connected regions with an area less than 100 by the concave point detection and segmentation algorithm for adhering grains in a preferred embodiment of the present invention;
[0053] Figure 5 It is a binary grain image of the concave point detection and segmentation algorithm for adhering grains in a preferred embodiment of the present invention, including the connected region Ω of the first type of grains I ;
[0054] Figure 6 It is a binary grain image of the concave point detection and segmentation algorithm for adhering grains in a preferred embodiment of the present invention, including the connected region Ω of the second type of grains II ;
[0055] Figure 7 It is an example image of taking out a grain connected region ω from Ω II by the concave point detection and segmentation algorithm for adhering grains in a preferred embodiment of the present invention; i
[0056] Figure 8 is the contour point p of the concave point detection and segmentation algorithm for adhering grains in a preferred embodiment of the present invention i 、p i1 、p i2 ; example image
[0057] Figure 9 is the example image of circle C of the concave point detection and segmentation algorithm for adhering grains in a preferred embodiment of the present invention
[0058] Figure 10 is the concave point detection and segmentation algorithm for adhering grains in a preferred embodiment of the present invention arc and arc; example image
[0059] Figure 11 is the example image of the curve segment division of the connected region contour line of the concave point detection and segmentation algorithm for adhering grains in a preferred embodiment of the present invention
[0060] Figure 12 is the ellipse fitting image of the concave point detection and segmentation algorithm for adhering grains in a preferred embodiment of the present invention
[0061] Figure 13 is Ω generated after the ellipse fitting segmentation of the connected region of the concave point detection and segmentation algorithm for adhering grains in a preferred embodiment of the present invention II example binary image
[0062] Figure 14 is the final segmentation result example image of the connected region Ω of the second type of grains of the concave point detection and segmentation algorithm for adhering grains in a preferred embodiment of the present invention II ; final segmentation result example image
[0063] Figure 15 is the final segmentation result example image of the original color grain image of the concave point detection and segmentation algorithm for adhering grains in a preferred embodiment of the present invention Detailed implementation manners
[0064] In order to make the technical problems, technical solutions and beneficial effects to be solved by the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention
[0065] In the following description, specific details such as specific internal programs and technologies are presented for the purpose of illustration rather than limitation, so as to thoroughly understand the embodiments of the present invention. However, those skilled in the art should understand that the present invention can also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to avoid unnecessary details from hindering the description of the present invention.
[0066] As Figure 1 shown, a preferred embodiment of the present invention provides a concave point detection and segmentation algorithm for adhering grains, including the following steps:
[0067] Step 1: Under normal light, collect color grain images and allow adhesion between grains; specifically, place the grains on a non-reflective black background cloth and allow adhesion between grains;
[0068] Under normal light, place the mobile phone directly above the grains to take pictures and obtain color grain images, as Figure 2 shown.
[0069] Step 2: Convert the color grain images into binary grain images; specifically including: adding the red value, green value, and blue value of each pixel in the color grain images to obtain m. When m≥200, the pixel is regarded as a grain and represented by 1. On the contrary, when m<200, the pixel is regarded as the background and represented by 0, so as to convert the color grain images as Figure 2 shown into binary grain images as Figure 3 shown.
[0070] Step 3: Count the area of each grain connected region in the binary grain images and delete the connected regions with an area less than 100; specifically including the following steps:
[0071] For the binary grain images obtained in Step 2, count the number of pixels included in each connected region with a pixel value equal to 1, and take the number of pixels as the area of the connected region;
[0072] Delete the connected regions with an area less than 100, and the result is as Figure 4 shown.
[0073] Step 4: Take the area of the smallest grain connected region in the grain connected region area after deleting the connected regions with an area less than 100 as the area S0 of a single grain, and then calculate the perimeter L0 of a single grain according to S0; specifically including:
[0074] According to the area of each grain connected region obtained in Step 3, take the area of the smallest grain connected region in the grain connected region area after deleting the connected regions with an area less than 100 as the area S0 of a single grain;
[0075] The shape of the grain can be regarded as an ellipse. For grains of a fixed variety, the ratio of the length a of the major semi-axis to the length b of the minor semi-axis of the corresponding ellipse is a fixed value η, that is, a = ηb; according to the ellipse area formula S0 = πab, we get b = , and further according to the ellipse perimeter formula L = 2πb + 4(a - b), the perimeter L0 of a single grain is [2π + 4(η - 1)] . For example, in Figure 4 the binary grain image shown, the area of the smallest grain connected region is 995, so S0 = 995; for Figure 4 the grains of a fixed variety shown, the ratio η of the length a of the major semi-axis to the length b of the minor semi-axis of the corresponding ellipse is about 2.5. Substituting S0 = 995 into the ellipse area formula S0 = πab, we get the length b of the minor semi-axis = = 11.2555. From a = ηb, we get a = 28.1389, and thus the perimeter L0 of a single grain is [2π + 4(η - 1)] = 138.254.
[0076] Step Five: Divide the grain connected regions in the binary grain image into two categories. The first category of grain connected region Ω I refers to the grain connected region that contains only a single grain, and the second category of grain connected region Ω II refers to the grain connected region that contains two or more adhered grains; specifically, it includes the following steps:
[0077] According to the area of each grain connected region obtained in Step Three, when the area S of the grain connected region is < 1.2S0, then this grain connected region contains only a single grain, and this connected region is regarded as the first category of grain connected region Ω I ; when the area S of the grain connected region is ≥ 1.2S0, then this grain connected region contains two or more adhered grains, and this connected region is regarded as the second category of grain connected region Ω II . For example, in Figure 4 the binary grain image shown, the area of a single grain is S0 = 995, 1.2S0 = 1194, Figure 4 there is a grain connected region with an area value of 997, and its area < 1.2S0. Therefore, this grain connected region is regarded as the first category of grain connected region Ω I ; in addition, Figure 4 there is a grain connected region with an area value of 3016, and its area > 1.2S0. Therefore, this grain connected region is regarded as the second category of grain connected region Ω II .
[0078] As Figure 5 shown, it is a binary grain image containing the first category of grain connected region. From Figure 5As can be seen, the Class I grain connected region contains only a single grain; as Figure 6 shown, it is a binary grain image containing the Class II grain connected region. As can be seen from Figure 6 , the Class II grain connected region contains two or more adhering grains.
[0079] Step Six: Extract the contour of the grain connected region belonging to Ω II ; specifically, it includes the following steps:
[0080] (1) Take out a grain connected region ω II from Ω i ;
[0081] (2) Calculate the sum of the eight-neighborhoods of each point in the grain connected region, and take the points with the result less than or equal to 6 as candidate points; here, the eight-neighborhood of a certain point refers to the four points above, below, left, and right of this point, as well as the four points in the upper left, upper right, lower left, and lower right, and the sum of the eight-neighborhoods is the sum of the values of these eight points;
[0082] (3) Denote the leftmost candidate point as a, mark it as a contour point of the grain connected region, and take point a as the current point p0;
[0083] (4) With the current point p0 as the center, arbitrarily select a candidate point p1 in the eight-neighborhood of p0. If point p1 has not been marked as a contour point, then mark point p1 as a contour point of the grain connected region, and take point p1 as the current point p0;
[0084] (5) Repeat step (4) until point a appears in the eight-neighborhood of the current point p0, then the contour extraction is completed.
[0085] To facilitate the understanding of the above contour extraction algorithm, an example is given here. Assume a binary image BW of size 7×7, and the image BW is represented by a matrix as:
[0086]
[0087] For each point with a value equal to 1 in the matrix BW, calculate the sum of its eight-neighborhoods to obtain a matrix BW8 of size 7×7:
[0088]
[0089] Take the points in the matrix BW8 with the result less than or equal to 6 as candidate points, assign the value 1 to the candidate points, and assign the value 0 to the remaining points to obtain a matrix BW2 of size 7×7:
[0090]
[0091] Mark the leftmost candidate point a in the matrix BW2 as a contour point of the grain connected region. The coordinates of point a are (3, 2), that is, point a is located at the position of the second column in the third row of the matrix BW2. Take point a as the current point p0. Here, it should be noted that when there are multiple leftmost points, for example, there are 3 leftmost points in BW2, it is stipulated to take the uppermost one as the candidate point a.
[0092] Centered on the current point p0, there are two candidate points in the eight-neighborhood of p0. Arbitrarily select a candidate point p1. The coordinates of candidate point p1 are (2, 3), that is, point p1 is located at the position of the third column in the second row of the matrix BW2, and point p1 has not been marked as a contour point. Mark point p1 as a contour point of the grain connected region and take point p1 as the current point p0.
[0093] Repeatedly perform the positioning operation of the next candidate point until point a appears in the eight-neighborhood of the current point p0. At this time, the coordinates of the current point p0 are (4, 2), and the contour extraction is completed. The obtained ordered set of contour points is:
[0094] {(3,2),(2,3),(2,4),(2,5),(3,6),(4,6),(5,6),(6,5),(6,4),(6,3),(5,2),(4,2)}
[0095] Step Seven: Detect the concave points of the grain connected regions belonging to Ω II Specifically, it includes the following steps:
[0096] (1) Take out a grain connected region ω II from Ω i ;
[0097] (2) Traverse each contour point p i on ω i obtained in Step Six. Taking p i as the reference point, take the 7th point p i1 forward along the contour, and then take the 7th point p i2 backward along the contour;
[0098] (3) Construct a circle C with p i as the center and the distance |p i p i1 | between p i and p i1 as the radius, and take 360 points at equal angular intervals of 1° on the circle C;
[0099] (4) Calculate the point i1 on the circle C that is closest to p , and calculate the point on the circle C that is closest to p i2The closest point ;
[0100] (5) and divide the circle C into and two arcs, count the number n1 of points on the arc whose value is equal to 1, and then count the number n2 of points on the other arc whose value is equal to 1. Take the larger of n1 and n2 as the angle of the contour point p i ;
[0101] (6) Compare the angle θ i of each contour point p i on ω i with the angles θ i-1 , θ i+1 of its previous and next contour points. When θ i > θ i-1 , and θ i > θ i+1 , and θ i > 220, then take the contour point p i as the concave point of the grain connected region to which p i belongs.
[0102] To facilitate the understanding of the above concave point detection algorithm, an example is given here. Take out a grain connected region ω Figure 7 from the type II grain connected region shown in i , that is, the grain connected region pointed by the arrow.
[0103] Traverse each contour point p i on ω i . Taking p i as the reference point, take the 7th point p i1 forward along the contour, and then take the 7th point p i2 backward along the contour. As shown in Figure 8 , the current contour point p i is marked with "o" and its coordinates are (824, 790). The point p i1 is the position marked with "*" pointed by the arrow, and its coordinates are (829, 783). The point p i2 is the position marked with "+" pointed by the arrow, and its coordinates are (818, 784).
[0104] As shown in Figure 9 , construct a circle with p i as the center and the distance |p i to p i1 as the radius, that is, |p i p i1A circle C with a radius of |p| is drawn, and 360 points are taken at equal angular intervals of 1° on the circle C. The polar coordinate equation of a circle with the center at the origin can be expressed as:
[0105]
[0106] where r is the radius of the circle, and θ is the polar angle in the counterclockwise direction. Thus, the abscissas of the 360 points on the circle C with a radius of |p| i p i1 = 8.6 can be represented by a matrix X as:
[0107] X=[8.599 8.595 8.588 8.579 8.567 8.553 8.536 8.516 8.494 8.469 8.4428.412 8.38 8.345 8.307 8.267 8.224 8.179 8.131 8.081 8.029 7.974 7.916 7.8567.794 7.73 7.663 7.593 7.522 7.448 7.372 7.293 7.213 7.13 7.045 6.958 6.8686.777 6.683 6.588 6.491 6.391 6.29 6.186 6.081 5.974 5.865 5.755 5.642 5.5285.412 5.295 5.176 5.055 4.933 4.809 4.684 4.557 4.429 4.3 4.169 4.037 3.9043.77 3.635 3.498 3.36 3.222 3.082 2.941 2.8 2.658 2.514 2.37 2.226 2.0811.935 1.788 1.641 1.493 1.345 1.197 1.048 0.899 0.75 0.6 0.45 0.3 0.15 0 -0.15 -0.3 -0.45 -0.6 -0.75 -0.899 -1.048 -1.197 -1.345 -1.493 -1.641 -1.788 -1.935 -2.081 -2.226 -2.37 -2.514 -2.658 -2.8 -2.941 -3.082 -3.222 -3.36 -3.498 -3.635 -3.77 -3.904 -4.037 -4.169 -4.3 -4.429 -4.557 -4.684 -4.809 -4.933 -5.055 -5.176 -5.295 -5.412 -5.528 -5.642 -5.755 -5.865 -5.974 -6.081 -6.186 -6.29 -6.391 -6.491 -6.588 -6.683 -6.777 -6.868 -6.958 -7.045 -7.13 -7.213 -7.293 -7.372 -7.448 -7.522 -7.593 -7.663 -7.73 -7.794 -7.856 -7.916 -7.974 -8.029 -8.081 -8.131 -8.179 -8.224 -8.267 -8.307 -8.345 -8.38 -8.412 -8.442 -8.469 -8.494 -8.516 -8.536 -8.553 -8.567 -8.579 -8.588 -8.595 -8.599 -8.6 -8.599 -8.595 -8.588 -8.579 -8.567 -8.553 -8.536 -8.516 -8.494 -8.469 -8.442 -8.412 -8.38 -8.345 -8.307 -8.267 -8.224 -8.179 -8.131 -8.081 -8.029 -7.974 -7.916 -7.856 -7.794 -7.73 -7.663 -7.593 -7.522 -7.448 -7.372 -7.293 -7.213 -7.13 -7.045 -6.958 -6.868 -6.777 -6.683 -6.588 -6.491 -6.391 -6.29 -6.186 -6.081 -5.974 -5.865 -5.755 -5.642 -5.528 -5.412 -5.295 -5.176 -5.055 -4.933 -4.809 -4.684 -4.557 -4.429 -4.3 -4.169 -4.037 -3.904 -3.77 -3.635 -3.498 -3.36 -3.222 -3.082 -2.941 -2.8 -2.658 -2.514 -2.37 -2.226 -2.081 -1.935 -1.788 -1.641 -1.493 -1.345 -1.197 -1.048 -0.899 -0.75 -0.6 -0.45 -0.3-0.15 0 0.15 0.3 0.45 0.6 0.75 0.899 1.048 1.197 1.345 1.493 1.641 1.7881.935 2.081 2.226 2.37 2.514 2.658 2.8 2.941 3.082 3.222 3.36 3.498 3.6353.77 3.904 4.037 4.169 4.3 4.429 4.557 4.684 4.809 4.933 5.055 5.176 5.2955.412 5.528 5.642 5.755 5.865 5.974 6.081 6.186 6.29 6.391 6.491 6.588 6.683 6.777 6.868 6.958 7.045 7.13 7.213 7.293 7.372 7.448 7.522 7.593 7.663 7.73 7.794 7.856 7.916 7.974 8.029 8.081 8.131 8.179 8.224 8.267 8.307 8.345 8.38 8.412 8.442 8.469 8.494 8.516 8.536 8.553 8.567 8.579 8.588 8.595 8.599 8.6].
[0108] The vertical coordinates of 360 points on the circle C can be represented by the matrix Y as follows:
[0109] Y=[-0.15 -0.3 -0.45 -0.6 -0.75 -0.899 -1.048 -1.197 -1.345 -1.493 -1.641 -1.788 -1.935 -2.081 -2.226 -2.37 -2.514 -2.658 -2.8 -2.941 -3.082 -3.222 -3.36 -3.498 -3.635 -3.77 -3.904 -4.037 -4.169 -4.3 -4.429 -4.557 -4.684 -4.809 -4.933 -5.055 -5.176 -5.295 -5.412 -5.528 -5.642 -5.755 -5.865 -5.974 -6.081 -6.186 -6.29 -6.391 -6.491 -6.588 -6.683 -6.777 -6.868 -6.958 -7.045 -7.13 -7.213 -7.293 -7.372 -7.448 -7.522 -7.593 -7.663 -7.73 -7.794 -7.856 -7.916 -7.974 -8.029 -8.081 -8.131 -8.179 -8.224 -8.267 -8.307 -8.345 -8.38 -8.412 -8.442 -8.469 -8.494 -8.516 -8.536 -8.553 -8.567 -8.579 -8.588 -8.595 -8.599 -8.6 -8.599 -8.595 -8.588 -8.579 -8.567 -8.553 -8.536 -8.516 -8.494 -8.469 -8.442 -8.412 -8.38 -8.345 -8.307 -8.267 -8.224 -8.179 -8.131 -8.081 -8.029 -7.974 -7.916 -7.856 -7.794 -7.73 -7.663 -7.593 -7.522 -7.448 -7.372 -7.293 -7.213 -7.13 -7.045 -6.958 -6.868 -6.777 -6.683 -6.588 -6.491 -6.391 -6.29 -6.186 -6.081 -5.974 -5.865 -5.755 -5.642 -5.528 -5.412 -5.295 -5.176 -5.055 -4.933 -4.809 -4.684 -4.557 -4.429 -4.3 -4.169 -4.037 -3.904 -3.77 -3.635 -3.498 -3.36 -3.222 -3.082 -2.941 -2.8 -2.658 -2.514 -2.37 -2.226-2.081 -1.935 -1.788 -1.641 -1.493 -1.345 -1.197 -1.048 -0.899 -0.75 -0.6 -0.45 -0.3 -0.15 -0 0.15 0.3 0.45 0.6 0.75 0.899 1.048 1.197 1.345 1.493 1.6411.788 1.935 2.081 2.226 2.37 2.514 2.658 2.8 2.941 3.082 3.222 3.36 3.4983.635 3.77 3.904 4.037 4.169 4.3 4.429 4.557 4.684 4.809 4.933 5.055 5.1765.295 5.412 5.528 5.642 5.755 5.865 5.974 6.081 6.186 6.29 6.391 6.491 6.5886.683 6.777 6.868 6.958 7.045 7.13 7.213 7.293 7.372 7.448 7.522 7.593 7.6637.73 7.794 7.856 7.916 7.974 8.029 8.081 8.131 8.179 8.224 8.267 8.307 8.3458.38 8.412 8.442 8.469 8.494 8.516 8.536 8.553 8.567 8.579 8.588 8.595 8.5998.6 8.599 8.595 8.588 8.579 8.567 8.553 8.536 8.516 8.494 8.469 8.442 8.4128.38 8.345 8.307 8.267 8.224 8.179 8.131 8.081 8.029 7.974 7.916 7.856 7.7947.73 7.663 7.593 7.522 7.448 7.372 7.293 7.213 7.13 7.045 6.958 6.868 6.7776.683 6.588 6.491 6.391 6.29 6.186 6.081 5.974 5.865 5.755 5.642 5.528 5.412 5.295 5.176 5.055 4.933 4.809 4.684 4.557 4.429 4.3 4.169 4.037 3.904 3.77 3.635 3.498 3.36 3.222 3.082 2.941 2.8 2.658 2.514 2.37 2.226 2.081 1.935 1.788 1.641 1.493 1.345 1.197 1.048 0.899 0.75 0.6 0.45 0.3 0.15 0].[[]]
[0110] Calculate the point on the circle C among 360 points that is closest to p i1 The closest point to obtain the point with coordinates (5.412, -6.684). Calculate the point on the circle C among 360 points that is closest to p i2 The closest point to obtain the point with coordinates (-6.186, -5.974).
[0111] As Figure 10 shown, and divide the circle C into and two arcs. The dashed line segment represents the arc, and the solid line segment represents the arc. Count the number n1 of points with a value of 1 on the arc, and the value of n1 is 275. Then count the number n2 of points with a value of 1 on the arc, and the value of n2 is 14. Take the larger of n1 and n2, which is 275, as the angle θ i of the contour point p i .
[0112] Next, compare the angle θ i of p i with the angles θ i-1 , θ i+1 of its previous and subsequent contour points. At this time, the value of θ i-1 is 268, and the value of θ i+1 is 270, satisfying θ i > θ i-1 , and θ i > θ i+1 , and θ i > 220. Then take the contour point p i as the concave point of the grain connected region to which p i belongs.
[0113] Step 8: Use ellipse fitting for the curve segments on the connected region of grains, and use the fitted ellipse to segment out the connected region of the first type of grains Ω I , for the remaining connected region of grains (the remaining connected region of grains may belong to the first type or the second type. Therefore, return to Step 5 to continue judging the grain type), delete the connected regions with an area less than 100, and then return to Step 5 until all the connected regions of the first type of grains Ω I are segmented out from the color grain image; the specific steps are as follows:
[0114] (1) The concave points on the connected region of grains divide the region contour into several curve segments;
[0115] (2) Count the number of contour points for each curve segment and use this number as the length of the curve segment;
[0116] (3) For the curve segments with a length greater than 0.5L0, use ellipse fitting to divide the connected region of grains into two parts. Consider the part of the connected region of grains located inside the fitted ellipse as the connected region of the first type of grains Ω I , for the remaining connected region of grains, delete the connected regions with an area less than 100;
[0117] (4) Then return to Step 5 until all the connected regions of the first type of grains Ω I are segmented out from the color grain image.
[0118] To facilitate the understanding of the above ellipse fitting segmentation algorithm, an example is given here. As Figure 11 shown in the figure is an image in which the contour line of the connected region is divided into several curve segments. The concave points on the connected region of grains are used to divide the region contour into curve segments S1, S2, S3, S4, S5, S6, S7, and S8. Among them, S1, S3, S5, and S7 are represented by solid lines respectively, and S2, S4, S6, and S8 are represented by dashed lines respectively.
[0119] Count the number of contour points for each curve segment and use this number as the length of the curve segment. The lengths of the curve segments S1, S2, S3, S4, S5, S6, S7, and S8 can be obtained as 109, 39, 33, 113, 16, 104, 46, and 54 respectively.
[0120] The value of L0 for a single grain is 138.254, then 0.5L0 is equal to 69.127. Therefore, only the lengths of the curve segments S1, S4, and S6 satisfy the condition of being greater than 0.5L0. Direct least-squares ellipse fitting is performed on these three curve segments. The ellipse fitting result is as Figure 12As shown, E1, E4, and E6 respectively correspond to the fitted ellipses of curve segments S1, S4, and S6. At this time, the grain connected region is divided into two parts. The part of the grain connected region located within the fitted ellipse is regarded as the first type of grain connected region Ω I , and for the remaining grain connected region, return to step five. As Figure 13 shown, among them, the area of the largest grain connected region is 1891, and this area is greater than 1.2S0. Therefore, this part of the grain connected region is regarded as the second type of grain connected region Ω II , and the areas of the remaining grain connected regions are all less than 100, so this part of the grain connected region is directly deleted.
[0121] As Figure 14 shown is the final segmentation result obtained for the second type of grain connected region shown in Figure 11 by the above method.
[0122] When using the direct least squares method to perform ellipse fitting on a curve segment, the form of the ellipse polynomial function is as follows:
[0123]
[0124] Let
[0125]
[0126]
[0127] Then the ellipse equation can be expressed as:
[0128]
[0129] Then the optimization problem of ellipse fitting can be expressed as:
[0130]
[0131] where D represents a data sample set of size n×6, n is the number of samples, 6 is the dimension, β is the parameter of the ellipse equation, and H is a constant matrix of size 6×6:
[0132]
[0133] Next, by solving the minimization constraint problem, the coefficient matrix β of the ellipse can be obtained, thereby obtaining the ellipse corresponding to each curve segment.
[0134] Extract all the first type of grain connected regions Ω Figure 2 from the color grain image, and obtain the grain segmentation result image as I shown in Figure 15 .
[0135] Table 1 shows the results obtained by measuring 18 images of adhered grains using the method and device of the present invention. These 18 images include different numbers of grains and different degrees of adhesion. As can be seen from Table 1, among the 18 grain images, 9 images have an accuracy rate of 100%, and the average accuracy rate is 98.72%. In short, the algorithm provided by the present invention has achieved a good segmentation effect.
[0136] Table 1 Measurement results of the number of grains in 18 grain images
[0137] Image Number Actual Number of Grains Grain Measurement Accuracy Rate (%) 1 20 20 100 2 23 23 100 3 25 25 100 4 30 30 100 5 35 34 97.14 6 40 40 100 7 45 44 97.78 8 50 48 96 9 55 55 100 10 65 64 98.46 11 68 68 100 12 70 69 98.57 13 75 73 97.33 14 80 80 100 15 85 85 100 16 90 88 97.78 17 95 92 96.84 18 100 97 97
[0138] The preferred specific embodiments of the present invention have been described in detail above. It should be understood that those of ordinary skill in the art can make many modifications and variations based on the concept of the present invention without creative labor. Therefore, all technical solutions that can be obtained by those skilled in the art in the technical field of the present invention based on the concept of the present invention through logical analysis, reasoning, or limited experiments on the basis of the prior art should be within the protection scope determined by the claims.
Claims
1. An indentation detection and segmentation algorithm for adhering grains, characterized in that, It includes the following steps: Step 1: Under normal light, collect color grain images and allow the grains to stick together. Step 2: Convert the color grain images into binary grain images. Step 3: Count the area of each grain connected region in the binary grain images and delete the connected regions with an area less than 100. Step 4: Take the area of the smallest grain connected region in the grain connected region areas after deleting the connected regions with an area less than 100 as the area S0 of a single grain, and then calculate the perimeter L0 of a single grain according to S0. Step 5: Classify the grain connected regions in the binary grain image into two categories. The first category of grain connected regions Ω I It means that the grain connected area only contains a single grain, and the type II grain connected area Ω II It means that the grain connected area contains more than two adhered grains; Step 6: Extract the contours of the grain connected regions belonging to Ω II ; Step Seven, detect the concave points of the grain connected regions belonging to Ω II ; specifically, it includes the following steps: (1) Take out a grain-connected region ω from Ω II ; i (2) Traverse each contour point p on ω obtained in Step 6 i and, taking p i as the reference point, take the 7th point p i forward along the contour, and then take the 7th point p i1 backward along the contour; i2 (3) Construct a circle C with center at p i and radius equal to the distance between p i and p i1 , that is, |p i p i1 |. Then take 360 points at equal angular intervals of 1° on the circle C; (4) Calculate the point among the 360 points on circle C that is closest to p i1 the point closest to the distance , calculate the point among the 360 points on circle C that is closest to p i2 the point closest to the distance ; (5) and divide the circle C into and two arcs, count the number n1 of points on the arc whose values are equal to 1, and then count the number n2 of points on the arc whose values are equal to 1, and take the larger of n1 and n2 as the angle of the contour point p i of; (6) Compare the angles θ of each contour point p on ω i with the angles θ of its adjacent front and rear contour points i ; when θ i > θ i-1 , θ i+1 > θ i , and θ i-1 > 220, then regard the contour point p i as the concave point of the grain connected region to which p i+1 belongs; i i i Step 8: Use elliptical fitting for the curve segments on the grain connected regions, and use the fitted ellipses to segment out the first type of grain connected region Ω I , for the remaining grain connected regions, delete the connected regions with an area less than 100, and then return to Step 5 until all the first type of grain connected regions Ω I are segmented out from the color grain image; the specific steps are as follows: (1) The concave points on the grain connected region divide the region contour into several curve segments. (2) Count the number of contour points for each curve segment and take this number as the length of the curve segment. (3) For a curve segment with a length greater than 0.5L0, elliptical fitting is adopted to divide the grain connected region into two parts. One part of the grain connected region located within the fitted ellipse is regarded as the first type of grain connected region Ω I For the remaining grain connected regions, the connected regions with an area less than 100 are deleted; (4) Return to step five again until all the connected regions Ω of the first type of grain are I segmented from the color grain image.
2. The concave point detection and segmentation algorithm for adhering grains according to claim 1, characterized in that, In Step 1, under normal light, collect color grain images and allow the grains to stick together, which specifically includes the following steps: Place the grains on a non-reflective black background cloth and allow the grains to stick together. Under normal light, place the mobile phone directly above the grains to take pictures to obtain color grain images.
3. The concave point detection and segmentation algorithm for adhering grains according to claim 2, wherein, In Step 2, convert the color grain images into binary grain images, which specifically includes the following steps: Add the red value, green value, and blue value of each pixel in the color grain images to get m. When m≥200, regard this pixel as a grain and represent it with 1. On the contrary, when m<200, regard this pixel as the background and represent it with 0, so as to convert the color grain images into binary grain images.
4. A concave point detection and segmentation algorithm for adhering grains according to claim 3, characterized in that, In Step 3, count the area of each grain connected region in the binary grain images and delete the connected regions with an area less than 100, which specifically includes the following steps: For the binary grain images obtained in Step 2, count the number of pixels included in each connected region with a pixel value equal to 1, and take the number of pixels as the area of the connected region. Delete the connected regions with an area less than 100.
5. The concave point detection and segmentation algorithm for adhering grains according to claim 4, characterized in that In Step 4, take the area of the smallest grain connected region in the grain connected region areas after deleting the connected regions with an area less than 100 as the area S0 of a single grain, and then calculate the perimeter L0 of a single grain according to S0, which specifically includes the following steps: According to the areas of the grain connected regions obtained in Step 3, take the area of the smallest grain connected region in the grain connected region areas after deleting the connected regions with an area less than 100 as the area S0 of a single grain. The shape of the grain can be regarded as an ellipse. For grains of a fixed variety, the ratio between the length a of the major semi-axis and the length b of the minor semi-axis of the corresponding ellipse is a fixed value η, that is, a = ηb; according to the ellipse area formula S0 = πab, we get b = , and further according to the ellipse perimeter formula L = 2πb + 4(a - b), the perimeter L0 of a single grain is [2π + 4(η - 1)] .
6. The concave point detection and segmentation algorithm for adhering grains according to claim 5, characterized in that In the fifth step, the connected regions of grains in the binary grain image are divided into two categories. The first category of grain connected region Ω I refers to the grain connected region that only contains a single grain. The second category of grain connected region Ω II refers to the grain connected region that contains two or more adhered grains, and specifically includes the following steps: According to the areas of the connected regions of each grain obtained in Step 3, when the area S of the connected region of the grain satisfies S < 1.2S0, the connected region of the grain only contains a single grain, and this connected region is regarded as the connected region of the first type of grain Ω I ; when the area S of the connected region of the grain satisfies S ≥ 1.2S0, the connected region of the grain contains two or more adhered grains, and this connected region is regarded as the connected region of the second type of grain Ω II .
7. The concave point detection and segmentation algorithm for adhering grains according to claim 6, characterized in that, In step six, extract the contour of the connected region of the grains belonging to Ω II which specifically includes the following steps: (1) Take out a grain-connected region ω from Ω II ; i (2) Calculate the sum of the eight neighborhoods of each point in the grain connected region, and take the points with the result less than or equal to 6 as candidate points. (3) Mark the leftmost candidate point a as the contour point of the grain connected region and take point a as the current point p0. (4) With the current point p0 as the center, arbitrarily select a candidate point p1 in the eight neighborhoods of p0. If point p1 has not been marked as a contour point, then mark point p1 as the contour point of the grain connected region and take point p1 as the current point p0. (5) Repeatedly perform step (4) until point a appears in the eight neighborhoods of the current point p0, then complete the contour extraction.