Wheat grain counting measurement method and system based on gray value comparison
Through the wheat ear grain counting method based on grayscale value comparison, the problems of low efficiency and insufficient information retention of traditional methods are solved, and higher counting accuracy and efficiency are achieved, which is suitable for automated ear grain analysis in the agricultural field.
Patent Information
- Application Number
- CN202110826470.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-07-21
- Publication Date
- 2025-01-10
- Estimated Expiration
- 2041-07-21
AI Technical Summary
The existing wheat ear grain counting method is inefficient and labor-intensive. Traditional methods are prone to missed identification or misidentification, and information retention is low.
Using the wheat ear grain counting method based on grayscale value comparison, the wheat ear image is obtained, and pre-processed to obtain the contour line and grayscale map, subdividing the spike grains, and calculating the spike grain positions through the grayscale mean array to reduce leakage recognition and misidentification.
It improves the accuracy and efficiency of ear grain counting, saves labor costs, better retains the original image information, and reduces misidentification and misidentification.
Smart Images

Figure CN113470104B_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of image processing, and in particular relates to a wheat grain counting and measuring method and system based on gray value comparison. Background Art
[0002] As the saying goes, food is the first necessity of the people, and wheat occupies a very important position among food crops. The yield and quality of wheat are related to the quality of human life. The shape of wheat ears, especially the length and number of grains, has a direct relationship with the yield of wheat. Studying the morphological characteristics of wheat ears has a positive significance for guiding production and specifying high-yield, high-quality and high-efficiency cultivation technology measures.
[0003] The geometric parameters of wheat ear morphology mainly include ear length and number of grains per ear. At present, there are few studies on wheat ear morphology measurement methods. The traditional method is mainly completed by manual counting, which is not only inefficient, but also labor-intensive and time-consuming. In the existing research on the market, the wheat ear morphology is identified through binary images, which has low information retention of wheat ears and is prone to missed or misidentified. Summary of the invention
[0004] In view of the shortcomings of the prior art, the present invention provides a wheat grain counting measurement method and system based on gray value comparison.
[0005] In order to solve the above technical problems, the present invention is solved by the following technical solutions:
[0006] A wheat grain counting measurement method based on gray value comparison comprises the following steps:
[0007] Acquire a single wheat ear image and separate the main wheat ear image;
[0008] Preprocessing the wheat ear main image to obtain a first wheat ear contour line, a second wheat ear contour line and a center line, and performing a second preprocessing based on the first wheat ear contour line, the second wheat ear contour line and the center line to obtain a first wheat ear grayscale image and a second wheat ear grayscale image and a first wheat ear binarization image and a second wheat ear binarization image;
[0009] The grains of the first wheat ear are subdivided based on the first wheat ear grayscale image and the first wheat ear binary image, and the grains of the second wheat ear are subdivided based on the second wheat ear grayscale image and the second wheat ear binary image, and the subdivided grains are summarized to obtain a new wheat ear subdivided binary image;
[0010] Based on the new wheat ear segmentation binary image, the grain positioning details of a single wheat ear are obtained, and then the grains of the wheat ear are counted.
[0011] As an implementable method, a single wheat ear image is obtained and the wheat ear main body image is separated as follows:
[0012] The single wheat ear image is obtained based on a black background plate;
[0013] The single wheat ear image is binarized, and the lower wheat stalk part and the upper wheat awn part are removed according to the length characteristics to obtain the main image of the wheat ear.
[0014] As an implementable method, the wheat ear main image is preprocessed to obtain a first wheat ear contour line, a second wheat ear contour line and a center line, and a second wheat ear grayscale image and a first wheat ear binarization image and a second wheat ear binarization image are obtained based on the first wheat ear contour line, the second wheat ear contour line and the center line. The specific steps include:
[0015] Separate the wheat ear main body brightness channel image based on the wheat ear main body image;
[0016] Binarization is performed on the wheat ear main body brightness channel image to obtain the contour lines and center line on both sides of the wheat ear main body, and the contour lines on both sides of the wheat ear main body are the first wheat ear contour line and the second wheat ear contour line;
[0017] Keeping the center line unchanged and shortening the distances from the first contour line and the second contour line to the center line respectively, to obtain a first adjusted contour line and a second adjusted contour line;
[0018] The first adjustment contour line and the center line as well as the second adjustment contour line and the center line are connected end to end and filled internally to obtain a first binary region image and a second binary region image;
[0019] The main brightness channel image of the wheat ear is processed to obtain a main grayscale image of the wheat ear, and then an adaptive binarization process is performed to obtain a main binary image of the wheat ear;
[0020] The first binary area image and the second binary area image are respectively used as masks and operated with the wheat ear main body grayscale image to obtain the first wheat ear grayscale image and the second wheat ear grayscale image. The first binary area image and the second binary area image are respectively used as masks and operated with the wheat ear main body binarized image to obtain the first wheat ear binarized image and the second wheat ear binarized image.
[0021] As an implementable method, obtaining the new wheat ear segmentation binary image includes the following steps:
[0022] Performing a second preprocessing on the first wheat ear binary image, the second wheat ear binary image, the first wheat ear grayscale image, and the second wheat ear grayscale image to obtain a first wheat ear subdivision binary image and a second wheat ear subdivision binary image;
[0023] The first wheat ear segmentation binary image and the second wheat ear segmentation binary image are summed to obtain a wheat ear segmentation binary image;
[0024] The first contour line and the second contour line are connected end to end and processed to obtain a wheat ear main area map;
[0025] The wheat ear main area map is used as a mask to perform operations on the wheat ear subdivision binary map to obtain a new wheat ear subdivision binary map.
[0026] As an implementable method, the first wheat ear segmentation binary image and the second wheat ear segmentation binary image are obtained by specifically performing the following steps:
[0027] Based on the first wheat ear grayscale image, a line connecting each point on the center line and a direction line with an inclination angle within a range of 50-80 degrees in the direction of the wheat awn are obtained to form a line segment set;
[0028] According to the first wheat ear binary image, the width of the first wheat ear along the center line at each tilt angle is obtained; according to the first wheat ear grayscale image and the first wheat ear binary image, the grayscale mean of the first wheat ear at each tilt angle is calculated to form a grayscale mean array;
[0029] According to the grayscale difference between the grain of the first ear of wheat and the gap, a series of minimum value points and maximum value points are obtained by traversing the grayscale mean array and forming a minimum value array and a maximum value array;
[0030] Based on the first wheat ear binary image and the center line, the line segment set, the minimum value of the minimum value array and the maximum value of the maximum value array, the maximum width of the first wheat ear on the direction line of the first wheat ear binary image is calculated, so as to obtain the first wheat ear subdivision binary image;
[0031] Based on the second wheat ear grayscale image, a line segment set is formed by obtaining the connecting line of each point on the center line and the direction line with an inclination angle within the range of 50-80 degrees in the direction of the wheat ear;
[0032] According to the second wheat ear binarization image, the width of the second wheat ear along the center line at each tilt angle is obtained; according to the second wheat ear grayscale image and the second wheat ear binarization image, the grayscale mean of the second wheat ear at each tilt angle is calculated to form a grayscale mean array;
[0033] According to the grayscale difference between the grain of the second ear of wheat and the gap, a series of minimum value points and maximum value points are obtained by traversing the grayscale mean array and forming a second minimum value array and a second maximum value array;
[0034] Based on the second wheat ear binary image and the center line, the line segment set, the minimum value of the second minimum value array and the maximum value of the second maximum value array, the maximum width of the second wheat ear on the direction line of the second wheat ear binary image is calculated to obtain the second wheat ear subdivision binary image.
[0035] As an implementable method, the method of obtaining the grain positioning details of the wheat ears based on the new wheat ear segmentation binary image and then counting the grains of the wheat ears includes the following steps:
[0036] Obtain a new wheat ear subdivision binary graph, calculate the number of connected domains and center points in the new wheat ear subdivision binary graph, and form a center point array;
[0037] Calculate the grayscale value of the corresponding point in the center point array in the main grayscale image of the wheat ear, and remove the center point that does not meet the requirements near the wheat awn by determining the difference between the center grayscale value and the surrounding grayscale value, and form a new center point array with the processed center points and save it;
[0038] The new center point array is mapped back to the single wheat ear image and drawn into the single wheat ear image to obtain the grain positioning details of the single wheat ear. The grains of the wheat ear are counted based on the positioning details to obtain the number of grains in the wheat ear.
[0039] A wheat grain counting and measuring system based on gray value comparison, comprising an image acquisition module, a first processing module, a second processing module and a positioning and counting module;
[0040] The image acquisition module is used to acquire a single wheat ear image and separate the wheat ear main body image;
[0041] The first processing module preprocesses the wheat ear main image to obtain a first wheat ear outline, a second wheat ear outline and a center line, and performs a second preprocessing based on the first wheat ear outline, the second wheat ear outline and the center line to obtain a first wheat ear grayscale image and a second wheat ear grayscale image and a first wheat ear binarization image and a second wheat ear binarization image;
[0042] The second processing module subdivides the grains of the first wheat ear based on the first wheat ear grayscale image and the first wheat ear binary image, and subdivides and summarizes the grains of the second wheat ear based on the second wheat ear grayscale image and the second wheat ear binary image, to obtain a new wheat ear subdivision binary image;
[0043] The positioning and counting module obtains the grain positioning details of a single wheat ear based on the new wheat ear segmentation binary image, and then counts the grains of the wheat ear.
[0044] As an implementable embodiment, the first processing module is configured as follows:
[0045] Separate the wheat ear main body brightness channel image based on the wheat ear main body image;
[0046] Binarization is performed on the wheat ear main body brightness channel image to obtain the contour lines and center line on both sides of the wheat ear main body, and the contour lines on both sides of the wheat ear main body are the first wheat ear contour line and the second wheat ear contour line;
[0047] Smoothing the first wheat ear contour line and the second wheat ear contour line to obtain a first contour line and a second contour line;
[0048] Keeping the center line unchanged and shortening the distances from the first contour line and the second contour line to the center line respectively, to obtain a first adjusted contour line and a second adjusted contour line;
[0049] The first adjustment contour line and the center line as well as the second adjustment contour line and the center line are connected end to end and filled internally to obtain a first binary region image and a second binary region image;
[0050] The main brightness channel image of the wheat ear is processed to obtain a main grayscale image of the wheat ear, and then an adaptive binarization process is performed to obtain a main binary image of the wheat ear;
[0051] The first binary area image and the second binary area image are respectively used as masks and operated with the wheat ear main body grayscale image to obtain the first wheat ear grayscale image and the second wheat ear grayscale image. The first binary area image and the second binary area image are respectively used as masks and operated with the wheat ear main body binarized image to obtain the first wheat ear binarized image and the second wheat ear binarized image.
[0052] A computer-readable storage medium stores a computer program, wherein the computer program, when executed by a processor, implements the following method steps:
[0053] Acquire a single wheat ear image and separate the main wheat ear image;
[0054] Preprocessing the wheat ear main image to obtain a first wheat ear contour line, a second wheat ear contour line and a center line, and performing a second preprocessing based on the first wheat ear contour line, the second wheat ear contour line and the center line to obtain a first wheat ear grayscale image and a second wheat ear grayscale image and a first wheat ear binarization image and a second wheat ear binarization image;
[0055] The grains of the first wheat ear are subdivided based on the first wheat ear grayscale image and the first wheat ear binary image, and the grains of the second wheat ear are subdivided based on the second wheat ear grayscale image and the second wheat ear binary image, and the subdivided grains are summarized to obtain a new wheat ear subdivided binary image;
[0056] Based on the new wheat ear segmentation binary image, the grain positioning details of a single wheat ear are obtained, and then the grains of the wheat ear are counted.
[0057] A wheat grain counting and measuring device based on grayscale value comparison comprises a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the following method steps are implemented:
[0058] Acquire a single wheat ear image and separate the main wheat ear image;
[0059] Preprocessing the wheat ear main image to obtain a first wheat ear contour line, a second wheat ear contour line and a center line, and performing a second preprocessing based on the first wheat ear contour line, the second wheat ear contour line and the center line to obtain a first wheat ear grayscale image and a second wheat ear grayscale image and a first wheat ear binarization image and a second wheat ear binarization image;
[0060] The grains of the first wheat ear are subdivided based on the first wheat ear grayscale image and the first wheat ear binary image, and the grains of the second wheat ear are subdivided based on the second wheat ear grayscale image and the second wheat ear binary image, and the subdivided grains are summarized to obtain a new wheat ear subdivided binary image;
[0061] Based on the new wheat ear segmentation binary image, the grain positioning details of a single wheat ear are obtained, and then the grains of the wheat ear are counted.
[0062] The present invention has significant technical effects due to the adoption of the above technical solution:
[0063] In the present invention, digital image processing technology is applied to automatic leaf area analysis in the agricultural field to obtain the grains of wheat ears, replacing manual analysis and instrument analysis, saving labor costs and equipment costs, and greatly improving work efficiency.
[0064] By performing single wheat ear grain segmentation based on wheat ear image, gap and grayscale contrast, compared with segmenting wheat ear grains based on binary images, the basic information of the original image can be better preserved, missed recognition and misrecognition can be reduced, and the accuracy of ear grain segmentation can be improved.
[0065] In addition, the method for acquiring images in the present invention is simple, and the images can be acquired by taking photos through a mobile terminal, which is very convenient to apply and is conducive to popularization and use.
[0066] In summary, the method based on the present invention can judge the number of grains in wheat ears by comparing the grayscale values of the gaps between wheat ears, which can greatly retain the information of the original image and reduce missed recognition and misrecognition. In addition, the method has a short test time, high accuracy, and good test results in the actual test process, which can greatly save the time and energy of agricultural researchers. BRIEF DESCRIPTION OF THE DRAWINGS
[0067] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0068] FIG1 is a flowchart of the overall algorithm processing of the present invention;
[0069] Figure 2Schematic diagram of obtaining a single wheat ear image in the present invention;
[0070] Figure 3 It is a schematic diagram of the step of separating the main part of the wheat ear according to the present invention;
[0071] Figure 4 It is a schematic diagram of separating the left and right parts of wheat ears from the center line;
[0072] Figure 5 The schematic diagram of segmenting wheat ears according to the width and grayscale mean;
[0073] Figure 6 Schematic diagram of wheat ear grain counting obtained based on the algorithm of the present invention;
[0074] Figure 7 It is a schematic diagram of the process of the present invention;
[0075] Figure 8 It is a system schematic diagram of the present invention. DETAILED DESCRIPTION
[0076] The present invention is further described in detail below in conjunction with embodiments. The following embodiments are for explanation of the present invention but the present invention is not limited to the following embodiments.
[0077] In the prior art, there are few studies on the measurement methods of wheat ear grains, and most of them are completed by manual counting, which is not only inefficient but also consumes a lot of manpower and time costs. However, with the application of image processing and big data intelligence, there are also methods to identify the shape of wheat ears such as wheat ear grains or ear length through binary images. However, after processing based on binary images, the information retention of wheat ears is low. Therefore, this method is easy to miss or misidentify, and cannot accurately obtain the shape of wheat ears.
[0078] Embodiment 1:
[0079] A wheat grain counting measurement method based on gray value comparison comprises the following steps:
[0080] S100, acquiring a single wheat ear image and separating the wheat ear main body image;
[0081] S200, preprocessing the wheat ear main image to obtain a first wheat ear contour line, a second wheat ear contour line, and a center line, and performing a second preprocessing based on the first wheat ear contour line, the second wheat ear contour line, and the center line to obtain a first wheat ear grayscale image and a second wheat ear grayscale image and a first wheat ear binarization image and a second wheat ear binarization image;
[0082] S300, subdividing the grains of the first wheat ear based on the first wheat ear grayscale image and the first wheat ear binary image, and subdividing the grains of the second wheat ear based on the second wheat ear grayscale image and the second wheat ear binary image, and summarizing them to obtain a new wheat ear subdivided binary image;
[0083] S400: obtaining the grain positioning details of a single wheat ear based on the new wheat ear segmentation binary image, and then counting the grains of the wheat ear.
[0084] Specifically, in the present invention, a single wheat ear image is obtained and the wheat ear main body image is separated, specifically:
[0085] The single wheat ear image is obtained based on a black background plate;
[0086] The single wheat ear image is binarized, and the lower wheat stalk part and the upper wheat awn part are removed according to the length characteristics to obtain the main image of the wheat ear.
[0087] In this embodiment, in order to process the image more conveniently and easily, a black background plate is used. Since the color difference between the black background plate and the wheat ears is very large, it is more convenient to process the image and the outline is clearer.
[0088] In one embodiment, the preprocessing of the wheat ear main image to obtain the first wheat ear contour line, the second wheat ear contour line and the center line, and the second preprocessing based on the first wheat ear contour line, the second wheat ear contour line and the center line to obtain the first wheat ear grayscale image and the second wheat ear grayscale image and the first wheat ear binarization image and the second wheat ear binarization image, specifically comprises the following steps:
[0089] S210, separating a wheat ear main body brightness channel image based on the wheat ear main body image;
[0090] S220, performing binarization processing on the brightness channel image of the wheat ear main body to obtain contour lines and a center line on both sides of the wheat ear main body, wherein the contour lines on both sides of the wheat ear main body are a first wheat ear contour line and a second wheat ear contour line;
[0091] S230, maintaining the center line and respectively shortening the distances from the first contour line and the second contour line to the center line to obtain a first adjusted contour line and a second adjusted contour line;
[0092] S240, respectively connecting the first adjusted contour line and the center line and the second adjusted contour line and the center line end to end and performing internal filling to obtain a first binary region image and a second binary region image;
[0093] S250, processing the wheat ear main body brightness channel image to obtain a wheat ear main body grayscale image, and then performing adaptive binarization processing to obtain a wheat ear main body binarization image;
[0094] S260, using the first binary area image and the second binary area image as masks respectively and performing operations with the wheat ear main body grayscale image to obtain the first wheat ear grayscale image and the second wheat ear grayscale image, using the first binary area image and the second binary area image as masks respectively and performing operations with the wheat ear main body binarized image to obtain the first wheat ear binarized image and the second wheat ear binarized image.
[0095] In this step, it can be known that the contour lines and center lines on both sides of the wheat ear body are first obtained by binarization, the contour lines on both sides of the wheat ear body are the first wheat ear contour line and the second wheat ear contour line, and then the first contour line and the second contour line are obtained by processing, and a series of processing is performed on the basis of the center line, and finally the first wheat ear grayscale image and the second wheat ear grayscale image and the first wheat ear binary image and the second wheat ear binary image are obtained, instead of directly obtaining the whole wheat ear binary image and the whole wheat ear binary image as in the traditional way. This method separates the wheat ears by the center line, and compared with segmenting the wheat ears and grains according to the binary image, it can better retain the basic information of the original image, reduce missed recognition and misrecognition, and improve the accuracy of grain segmentation.
[0096] In addition, the step of obtaining the new wheat ear segmentation binary image comprises the following steps:
[0097] S310, performing a second preprocessing on the first wheat ear binary image, the second wheat ear binary image, the first wheat ear grayscale image, and the second wheat ear grayscale image to obtain a first wheat ear subdivision binary image and a second wheat ear subdivision binary image;
[0098] S320, summing the first wheat ear segmentation binary image and the second wheat ear segmentation binary image to obtain a wheat ear segmentation binary image;
[0099] S330, connecting the first contour line and the second contour line end to end and processing them to obtain a wheat ear main area map;
[0100] S340, using the wheat ear main area image as a mask and performing calculations on the wheat ear subdivision binary image to obtain a new wheat ear subdivision binary image.
[0101] In the above step S310, the first wheat ear segmentation binary image and the second wheat ear segmentation binary image are obtained by the following specific steps:
[0102] S3110, based on the first wheat ear grayscale image, obtain the lines connecting each point on the center line and the direction lines with an inclination angle within the range of 50-80 degrees in the direction of the wheat awn to form a line segment set;
[0103] S3120, obtaining the width of the first wheat ear along the center line at each tilt angle according to the first wheat ear binarization image, calculating the grayscale mean of the first wheat ear at each tilt angle according to the first wheat ear grayscale image and the first wheat ear binarization image, and forming a grayscale mean array;
[0104] S3130, according to the grayscale difference between the grain of the first wheat ear and the gap, obtain a series of minimum value points and maximum value points by traversing the grayscale mean array and form a minimum value array and a maximum value array;
[0105] S3140, calculating the maximum width of the first wheat ear on the direction line of the first wheat ear binary image based on the first wheat ear binary image and the center line, the line segment set, the minimum value of the minimum value array and the maximum value of the maximum value array;
[0106] S3150, draw a center line vecMiddlePts in the first wheat ear binary image, the color is the background color, the width is 2 pixels, at the position of the center line corresponding to the minimum value array, draw a direction line, the color is the background color, the width is 5 pixels, at the position corresponding to the maximum value array, draw a direction line, the color is the foreground color, the width is 5 pixels, and the length of the direction line is the maximum width, to obtain the first wheat ear subdivision binary image;
[0107] S3160, based on the second wheat ear grayscale image, obtain the line connecting each point on the center line and the direction line with an inclination angle within the range of 50-80 degrees in the direction of the wheat awn to form a line segment set;
[0108] S3170, obtaining the width of the second wheat ear along the center line at each tilt angle according to the second wheat ear binarization image, calculating the grayscale mean of the second wheat ear at each tilt angle according to the second wheat ear grayscale image and the second wheat ear binarization image, and forming a grayscale mean array;
[0109] S3180, according to the grayscale difference between the grain of the second wheat ear and the gap, obtain a series of minimum value points and maximum value points by traversing the grayscale mean array and form a second minimum value array and a second maximum value array;
[0110] S3190, calculating the maximum width of the second wheat ear on the direction line of the second wheat ear binary image based on the second wheat ear binary image and the center line, the line segment set, the minimum value of the second minimum value array and the maximum value of the second maximum value array;
[0111] S3200. Draw a center line vecMiddlePts in the second wheat ear binary image. The color is the background color and the width is 2 pixels. At the position of the center line corresponding to the minimum value array, draw a direction line. The color is the background color and the width is 5 pixels. At the position corresponding to the maximum value array, draw a direction line. The color is the foreground color and the width is 5 pixels. The length of the direction line is the maximum width. The second wheat ear subdivision binary image is obtained.
[0112] This process is a detailed process of generating the first wheat ear subdivision binary image and the second wheat ear subdivision binary image. Through the above process, the first wheat ear subdivision binary image and the second wheat ear subdivision binary image can be accurately obtained.
[0113] In one embodiment, the method of counting the grains of wheat ears based on the ear-grain positioning details of the new wheat ear subdivision binary image comprises the following steps:
[0114] S410, obtaining a new wheat ear subdivision binary graph, calculating the number of connected domains and center points in the new wheat ear subdivision binary graph and forming a center point array;
[0115] S420, calculating the grayscale values of the corresponding points in the center point array in the main body grayscale image of the wheat ear, and removing the center points that do not meet the requirements and are located near the wheat awn by determining the difference between the center grayscale value and the surrounding grayscale values, and forming a new center point array with the processed center points and saving the new center point array;
[0116] S430, mapping the new center point array back to the single wheat ear image and drawing it into the single wheat ear image, obtaining the positioning details of the grains of the single wheat ear, and counting the grains of the wheat ear based on the positioning details to obtain the number of grains of the wheat ear.
[0117] See attached Figure 1-6 The method of the present invention is explained as follows:
[0118] Figure 1 This is a general process, which can be used as a reference. Figure 2-Figure 6 The method of the present invention is exemplified.
[0119] See also Figure 2 , obtain a single wheat ear image, the obtained image is recorded as img1, and image img1 is the single wheat ear image.
[0120] The specific implementation steps are:
[0121] S1.1. Place the wheat on a black background and take a photo with a mobile phone, camera or other terminal. This image is recorded as img11.
[0122] Remove the wheat awns and stalks from a single wheat ear image and separate the main wheat ear image, such as Figure 3 Specifically, the following steps may be referred to:
[0123] S2.1, obtain the processing result img11 of S1.1, perform binarization on img11, and obtain img21;
[0124] S2.2, obtain the processing result img21 of S2.1, scan the binary image from left to right, record the width of the foreground color of each row, remove the straw part at the bottom according to the width feature, and remember that the image obtained is img22;
[0125] S2.3. Obtain the processing result img22 of S2.2, calculate the average foreground color width of the middle 1 / 3 of the binary image after removing the wheat stalks, as the normal width of wheat ears, scan each row in the upper 1 / 3 of the binary image, calculate the proportion of the continuous foreground color width to the average width, and calculate the proportion of the continuous foreground color width to the foreground color width of the current row, as well as the proportion of the continuous foreground color width to the foreground color span on the left and right sides of the current row. By adjusting the ratio of the three values, remove excess wheat awns, and obtain the final wheat ear main image img23. Image img23 is the wheat ear main image.
[0126] Then, the two side contours are obtained based on the binary image of the wheat ear, and the center line is obtained based on the two side contours. Finally, the left and right parts of the wheat ear are separated based on the three contour lines. The segmentation result is as follows: Figure 4 As shown, the specific steps are as follows:
[0127] S3.1, obtain the wheat ear main body image img23 in S2.3, separate its brightness channel image, recorded as img31, and the image img31 is the brightness channel image of the wheat ear main body;
[0128] S3.2. Obtain the processing result img31 of S3.1, binarize the image, obtain the contour lines of the left and right sides of the wheat ear body according to the binary image, smooth the two contour lines, and save them in the arrays vecLeftPts and vecRightPts. The arrays vecLeftPts and vecRightPts are respectively the first wheat ear contour line and the set of the first wheat ear contour lines of all wheat ears. Calculate the center lines of the two contour lines and save them in the array vecMiddlePts. Similarly, the array vecMiddlePts is the set of the center lines of all wheat ears.
[0129] S3.3, obtain the corresponding lines in the processing results vecLeftPts, vecRightPts and vecMiddlePts of S3.2. Keep the center line unchanged, calculate the distance from the left and right contour lines to the center line, so that when the distance from the left and right contour point columns to the center line is greater than 10 pixels, adjust the left and right contour point columns to 0.6 times the original, and save the adjusted left and right contour lines in the arrays vecLeftPtsNew and vecRightPtsNew. The arrays vecLeftPtsNew and vecRightPtsNew store the first adjusted contour line and the second adjusted contour line;
[0130] S3.4, obtain the result image img31 of S3.1 and the first adjusted contour line, the second adjusted contour line and the center line of S3.3, connect the first adjusted contour line and the center line end to end, connect the second adjusted contour line and the center line end to end, draw them on a black background image of the same size as img31 and fill them with the foreground color, and obtain the regional images of the left and right parts of the wheat ears, which are recorded as img341 and img342 respectively, and img341 and img342 are the first binary regional image and the second binary regional image respectively;
[0131] S3.5. Obtain the wheat ear image img31 of S3.1, separate the L channel and V channel of the image img31, subtract the V channel image from the L channel to obtain a new grayscale image, recorded as img351, and perform an adaptive binarization operation on img351, recorded as img352. img352 is the binarized image of the wheat ear main body.
[0132] S3.6. Obtain images img341 and img342 of S3.4 and result images img351 and img352 of S3.5. Use img341 and img342 as masks respectively, and perform operations with img351 to obtain the left and right parts of the wheat ear grayscale images, which are recorded as imgGrayLeft and imgGrayRight respectively. imgGrayLeft and imgGrayRight are the first wheat ear grayscale image and the second wheat ear grayscale image respectively. Use img341 and img342 as masks respectively, and perform operations with img352 to obtain the left and right parts of the wheat ear binary images, which are recorded as imgBinaryLeft and imgBinaryRight respectively. imgBinaryLeft and imgBinaryRight are the first wheat ear binary image and the second wheat ear binary image.
[0133] Furthermore, according to the principle that the position of the wheat ear is where the average brightness is large and the gap between the wheat ears is where the average brightness is small, the wheat ears on both sides are subdivided. The subdivision results are as follows: Figure 4 As shown, the specific steps are:
[0134] S4.1. Subdivide the left and right parts of the ear grains. Only the left part is used for explanation below to obtain the processing result imgGrayLeft of S3.6 and the processing result vecMiddlePts of S3.2. Obtain the direction line with an inclination angle of 50-80 degrees between the line connecting each point on the center line vecMiddlePts and the direction of the wheat awn, and save it in the array vecDirectPts;
[0135] S4.2, obtain the processing result vecDirectPts of S4.1 and the processing results imgGrayLeft and imgBinaryLeft of S3.6, calculate the width of the left ear of wheat at each tilt angle on the center line vecMiddlePts according to the wheat ear binary image imgBinaryLeft, save the width in the array vecLefLength, calculate the grayscale mean of the left ear of wheat at each tilt angle according to the first wheat ear grayscale image imgGrayLeft and the first wheat ear binary image imgBinaryLeft, and save the grayscale mean in the array vecLeftGrayMean;
[0136] S4.3, obtain the result vecMiddlePts of S3.2 and the processing results imgBinaryLeft, vecLeftLength and vecLeftGrayMean of S4.2, obtain the upper and lower effective boundaries of the image according to the range of the foreground color of imgBinaryLeft, and then obtain the maximum width of the left ear of wheat according to veLeftLength, the maximum width is recorded as maxLength, the left ear of wheat is the first ear of wheat, and the right ear of wheat is the second ear of wheat, finally, according to the principle that the ear position with a large brightness mean is the ear position and the ear gap with a small brightness mean is the ear gap, the ears of wheat within the effective range are segmented, and the detailed segmentation process is as follows:
[0137] 1) Let the sequence number of the center line point column corresponding to the maximum brightness mean of vecLeftGrayMean be maxIndex. Starting from the maximum brightness mean position maxIndex, traverse the array vecLeftGrayMean downwards, and find the position of the minimum brightness mean closest to the maximum brightness mean within the length range of maxLength. Let this position be minIndex.
[0138] 2) Starting from the minimum brightness mean minIndex, continue to traverse the array vecLeftGrayMean downwards, and within the length range of maxLength, find the position of the maximum brightness mean closest to the minimum brightness mean, and record this position as maxIndex2;
[0139] 3) According to the above rules, traverse the array vecLeftGrayMean downward until the traversal ends, and then traverse the array vecLeftGrayMean upward starting from the maximum brightness mean position maxIndex according to the above rules;
[0140] 4) By traversing the array vecLeftGrayMean, a series of minimum points and a series of maximum points are obtained, and they are saved in the arrays vecMinValue and vecMaxValue. The arrays vecMinValue and vecMaxValue are the minimum value array and the maximum value array;
[0141] 5) Traverse the arrays vecMinValue and vecMaxValue, merge the two adjacent subscripts whose spacing is less than half of the average of the subscript spacing, and re-subdivide the two adjacent subscripts whose spacing is greater than 1.5 times the average according to the conditions, and the corresponding vecMaxValue is also updated accordingly.
[0142] S4.4. Obtain the center line and the direction point vecDirectPts corresponding to the center line in the first wheat ear binary image imgBinaryLeft in step S3.6 and vecMiddlePts in step S3.2, as well as the vecMinValue, vecMaxValue and maxLength in step S4.3. In the first wheat ear binary image imgBinaryLeft, draw the wheat ear center line vecMiddlePts, with the background color and 2 pixels in width. At the position of the center line corresponding to the array vecMinValue, draw the direction line, with the background color and 5 pixels in width. At the position corresponding to the array vecMaxValue, draw the direction line, with the foreground color and 5 pixels in width. The length of the direction line is maxLength. The processed image is recorded as img44. Figure img44 is the first wheat ear subdivision binary image.
[0143] S4.5. Perform similar processing on the right part of the wheat ear to obtain a subdivided binary image of the right side of the wheat ear, which is recorded as img45. Image img45 is the subdivided binary image of the second wheat ear.
[0144] S4.6, obtain img44, the result of step S4.4, and img45, the result of step S4.5, add the two images to obtain img46, which is a binary image of wheat ear segmentation;
[0145] S4.7. Obtain vecLeftPts and vecRightPts from step S3.2 and img46 from step S4.6. Connect the arrays vecLeftPts and vecRightPts end to end, draw them on a black background of the same size as img44, and then fill the holes with white to obtain the area map of the main body of the wheat ear, recorded as img471. img471 is the area map of the main body of the wheat ear. Use img471 as a mask to operate with img46 to correct the interference on both sides of the wheat ear and obtain a new binary image, recorded as img47. img47 is the new wheat ear subdivision binary image.
[0146] Finally, the grain count of wheat ears is performed based on the obtained ear-grain segmentation binary image and the number of connected domains in the binary image, as shown in Figure 6 As shown, the specific steps are as follows:
[0147] S5.1. Obtain the processing result img47 of step S4.7, calculate the number and center of connected domains in the image, save the center point of each connected domain in the array vecGrainPts, calculate the grayscale value of the point corresponding to the array vecGrainPts in the grayscale image, and eliminate the center point of the wheat ear that does not meet the requirements and is located near the wheat awn by determining the difference between the center grayscale value and the surrounding grayscale values, and save the processed center point in the array vecGrainPtsNew;
[0148] S5.2. Mapping the center point array vecGrainPtsNew back to the image of a single wheat ear and drawing it into the image of a single wheat ear can vividly display the positioning of the grains of the wheat ear.
[0149] The method based on the present invention can judge the number of grains in wheat ears by comparing the grayscale values of the gaps between wheat ears, which can greatly retain the information of the original image and reduce missed recognition and misrecognition. In addition, the method has a short test time, high accuracy and good test effect in the actual test process, which can greatly save the time and energy of agricultural researchers.
[0150] Embodiment 2:
[0151] A wheat grain counting and measuring system based on gray value comparison includes an image acquisition module 100, a first processing module 200, a second processing module 300 and a positioning and counting module 400;
[0152] The image acquisition module 100 is used to acquire a single wheat ear image and separate the wheat ear main body image;
[0153] The first processing module 200 preprocesses the wheat ear main image to obtain a first wheat ear contour line, a second wheat ear contour line and a center line, and performs a second preprocessing based on the first wheat ear contour line, the second wheat ear contour line and the center line to obtain a first wheat ear grayscale image and a second wheat ear grayscale image and a first wheat ear binarization image and a second wheat ear binarization image;
[0154] The second processing module 300 is configured to subdivide the grains of the first wheat ear based on the first wheat ear grayscale image and the first wheat ear binary image, and to subdivide and summarize the grains of the second wheat ear based on the second wheat ear grayscale image and the second wheat ear binary image, so as to obtain a new wheat ear subdivided binary image;
[0155] The positioning and counting module 400 obtains the grain positioning details of a single wheat ear based on the new wheat ear segmentation binary image, and then counts the grains of the wheat ear.
[0156] As an implementable embodiment, the first processing module 200 is configured as follows:
[0157] Separate the wheat ear main body brightness channel image based on the wheat ear main body image;
[0158] Binarization is performed on the wheat ear main body brightness channel image to obtain the contour lines and center line on both sides of the wheat ear main body, and the contour lines on both sides of the wheat ear main body are the first wheat ear contour line and the second wheat ear contour line;
[0159] Keeping the center line unchanged and shortening the distances from the first contour line and the second contour line to the center line respectively, to obtain a first adjusted contour line and a second adjusted contour line;
[0160] The first adjustment contour line and the center line as well as the second adjustment contour line and the center line are connected end to end and filled internally to obtain a first binary region image and a second binary region image;
[0161] The main brightness channel image of the wheat ear is processed to obtain a main grayscale image of the wheat ear, and then an adaptive binarization process is performed to obtain a main binary image of the wheat ear;
[0162] The first binary area image and the second binary area image are used as masks respectively and are operated with the main body grayscale image of the wheat ear to obtain the first wheat ear grayscale image and the second wheat ear grayscale image. The first binary area image and the second binary area image are used as masks respectively and are operated with the main body binary image of the wheat ear to obtain the first wheat ear binary image and the second wheat ear binary image.
[0163] In one embodiment, the image acquisition module 100 is configured to:
[0164] The single wheat ear image is obtained based on a black background plate;
[0165] The single wheat ear image is binarized, and the lower wheat stalk part and the upper wheat awn part are removed according to the length characteristics to obtain the main image of the wheat ear.
[0166] In one embodiment, the second processing module 300 is configured to:
[0167] Performing a second preprocessing on the first wheat ear binary image, the second wheat ear binary image, the first wheat ear grayscale image, and the second wheat ear grayscale image to obtain a first wheat ear subdivision binary image and a second wheat ear subdivision binary image;
[0168] The first wheat ear segmentation binary image and the second wheat ear segmentation binary image are summed to obtain a wheat ear segmentation binary image;
[0169] The first contour line and the second contour line are connected end to end and processed to obtain a wheat ear main area map;
[0170] The wheat ear main area map is used as a mask to perform operations on the wheat ear subdivision binary map to obtain a new wheat ear subdivision binary map.
[0171] As an implementable method, the first wheat ear segmentation binary image and the second wheat ear segmentation binary image are obtained by specifically performing the following steps:
[0172] Based on the first wheat ear grayscale image, a line connecting each point on the center line and a direction line with an inclination angle within a range of 50-80 degrees in the direction of the wheat awn are obtained to form a line segment set;
[0173] According to the first wheat ear binary image, the width of the first wheat ear along the center line at each tilt angle is obtained; according to the first wheat ear grayscale image and the first wheat ear binary image, the grayscale mean of the first wheat ear at each tilt angle is calculated to form a grayscale mean array;
[0174] According to the grayscale difference between the grain of the first ear of wheat and the gap, a series of minimum value points and maximum value points are obtained by traversing the grayscale mean array and forming a minimum value array and a maximum value array;
[0175] Based on the first wheat ear binary image and the center line, the line segment set, the minimum value of the minimum value array and the maximum value of the maximum value array, the maximum width of the first wheat ear on the direction line of the first wheat ear binary image is calculated, so as to obtain the first wheat ear subdivision binary image;
[0176] Based on the second wheat ear grayscale image, a line segment set is formed by obtaining the connecting line of each point on the center line and the direction line with an inclination angle within the range of 50-80 degrees in the direction of the wheat ear;
[0177] According to the second wheat ear binarization image, the width of the second wheat ear along the center line at each tilt angle is obtained; according to the second wheat ear grayscale image and the second wheat ear binarization image, the grayscale mean of the second wheat ear at each tilt angle is calculated to form a grayscale mean array;
[0178] According to the grayscale difference between the grain of the second ear of wheat and the gap, a series of minimum value points and maximum value points are obtained by traversing the grayscale mean array and forming a second minimum value array and a second maximum value array;
[0179] Based on the second wheat ear binary image and the center line, the line segment set, the minimum value of the second minimum value array and the maximum value of the second maximum value array, the maximum width of the second wheat ear on the direction line of the second wheat ear binary image is calculated to obtain the second wheat ear subdivision binary image.
[0180] In one embodiment, the positioning counting module 400 is configured to:
[0181] Obtain a new wheat ear subdivision binary graph, calculate the number of connected domains and center points in the new wheat ear subdivision binary graph, and form a center point array;
[0182] Calculate the grayscale value of the corresponding point in the center point array in the main grayscale image of the wheat ear, and remove the center point that does not meet the requirements near the wheat awn by determining the difference between the center grayscale value and the surrounding grayscale value, and form a new center point array with the processed center points and save it;
[0183] The new center point array is mapped back to the single wheat ear image and drawn into the single wheat ear image to obtain the grain positioning details of the single wheat ear. The grains of the wheat ear are counted based on the positioning details to obtain the number of grains in the wheat ear.
[0184] Embodiment 3:
[0185] A computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following method steps are implemented:
[0186] Acquire a single wheat ear image and separate the main wheat ear image;
[0187] Preprocessing the wheat ear main image to obtain a first wheat ear contour line, a second wheat ear contour line and a center line, and performing a second preprocessing based on the first wheat ear contour line, the second wheat ear contour line and the center line to obtain a first wheat ear grayscale image and a second wheat ear grayscale image and a first wheat ear binarization image and a second wheat ear binarization image;
[0188] The grains of the first wheat ear are subdivided based on the first wheat ear grayscale image and the first wheat ear binary image, and the grains of the second wheat ear are subdivided based on the second wheat ear grayscale image and the second wheat ear binary image, and the subdivided grains are summarized to obtain a new wheat ear subdivided binary image;
[0189] Based on the new wheat ear segmentation binary image, the grain positioning details of a single wheat ear are obtained, and then the grains of the wheat ear are counted.
[0190] In one embodiment, when the processor executes the computer program, the acquisition of a single wheat ear image and separation of the wheat ear main body image are implemented as follows:
[0191] The single wheat ear image is obtained based on a black background plate;
[0192] The single wheat ear image is binarized, and the lower wheat stalk part and the upper wheat awn part are removed according to the length characteristics to obtain the main image of the wheat ear.
[0193] In one embodiment, when the processor executes the computer program, the preprocessing of the wheat ear main image to obtain the first wheat ear contour line, the second wheat ear contour line and the center line is implemented, and the second preprocessing based on the first wheat ear contour line, the second wheat ear contour line and the center line is performed to obtain the first wheat ear grayscale image and the second wheat ear grayscale image and the first wheat ear binary image and the second wheat ear binary image, and the specific steps include:
[0194] Separate the wheat ear main body brightness channel image based on the wheat ear main body image;
[0195] Binarization is performed on the wheat ear main body brightness channel image to obtain the contour lines and center line on both sides of the wheat ear main body, and the contour lines on both sides of the wheat ear main body are the first wheat ear contour line and the second wheat ear contour line;
[0196] Smoothing the first wheat ear contour line and the second wheat ear contour line to obtain a first contour line and a second contour line;
[0197] Keeping the center line unchanged and shortening the distances from the first contour line and the second contour line to the center line respectively, to obtain a first adjusted contour line and a second adjusted contour line;
[0198] The first adjustment contour line and the center line as well as the second adjustment contour line and the center line are connected end to end and filled internally to obtain a first binary region image and a second binary region image;
[0199] The main brightness channel image of the wheat ear is processed to obtain a main grayscale image of the wheat ear, and then an adaptive binarization process is performed to obtain a main binary image of the wheat ear;
[0200] The first binary area image and the second binary area image are used as masks respectively and are operated with the main body grayscale image of the wheat ear to obtain the first wheat ear grayscale image and the second wheat ear grayscale image. The first binary area image and the second binary area image are used as masks respectively and are operated with the main body binary image of the wheat ear to obtain the first wheat ear binary image and the second wheat ear binary image.
[0201] In one embodiment, when the processor executes the computer program, the method of obtaining the new wheat ear segmentation binary image includes the following steps:
[0202] Performing a second preprocessing on the first wheat ear binary image, the second wheat ear binary image, the first wheat ear grayscale image, and the second wheat ear grayscale image to obtain a first wheat ear subdivision binary image and a second wheat ear subdivision binary image;
[0203] The first wheat ear segmentation binary image and the second wheat ear segmentation binary image are summed to obtain a wheat ear segmentation binary image;
[0204] The first contour line and the second contour line are connected end to end and processed to obtain a wheat ear main area map;
[0205] The wheat ear main area map is used as a mask to perform operations on the wheat ear subdivision binary map to obtain a new wheat ear subdivision binary map.
[0206] In one embodiment, when the processor executes the computer program, the steps of obtaining the first wheat ear segmentation binary image and the second wheat ear segmentation binary image are as follows:
[0207] Based on the first wheat ear grayscale image, a line connecting each point on the center line and a direction line with an inclination angle within a range of 50-80 degrees in the direction of the wheat awn are obtained to form a line segment set;
[0208] According to the first wheat ear binary image, the width of the first wheat ear along the center line at each tilt angle is obtained; according to the first wheat ear grayscale image and the first wheat ear binary image, the grayscale mean of the first wheat ear at each tilt angle is calculated to form a grayscale mean array;
[0209] According to the grayscale difference between the grain of the first ear of wheat and the gap, a series of minimum value points and maximum value points are obtained by traversing the grayscale mean array and forming a minimum value array and a maximum value array;
[0210] Based on the first wheat ear binary image and the center line, the line segment set, the minimum value of the minimum value array and the maximum value of the maximum value array, the maximum width of the first wheat ear on the direction line of the first wheat ear binary image is calculated;
[0211] Draw the center line vecMiddlePts in the first wheat ear binary image, with the background color and 2 pixels in width. Draw the direction line at the position of the center line corresponding to the minimum value array, with the background color and 5 pixels in width. Draw the direction line at the position corresponding to the maximum value array, with the foreground color and 5 pixels in width. The length of the direction line is the maximum width, and the first wheat ear subdivision binary image is obtained.
[0212] Based on the second wheat ear grayscale image, a line segment set is formed by obtaining the connecting line of each point on the center line and the direction line with an inclination angle within the range of 50-80 degrees in the direction of the wheat ear;
[0213] According to the second wheat ear binarization image, the width of the second wheat ear along the center line at each tilt angle is obtained; according to the second wheat ear grayscale image and the second wheat ear binarization image, the grayscale mean of the second wheat ear at each tilt angle is calculated to form a grayscale mean array;
[0214] According to the grayscale difference between the grain of the second ear of wheat and the gap, a series of minimum value points and maximum value points are obtained by traversing the grayscale mean array and forming a second minimum value array and a second maximum value array;
[0215] Based on the second wheat ear binary image and the center line, the line segment set, the minimum value of the second minimum value array and the maximum value of the second maximum value array, the maximum width of the second wheat ear on the direction line of the second wheat ear binary image is calculated;
[0216] Draw the center line vecMiddlePts in the second wheat ear binary image, with the background color and 2 pixels in width. Draw the direction line at the position of the center line corresponding to the minimum value array, with the background color and 5 pixels in width. Draw the direction line at the position corresponding to the maximum value array, with the foreground color and 5 pixels in width. The length of the direction line is the maximum width, and the second wheat ear subdivision binary image is obtained.
[0217] In one embodiment, when the processor executes the computer program, the method of realizing the location details of the grains of the wheat ears based on the new wheat ear segmentation binary image, and then counting the grains of the wheat ears, includes the following steps:
[0218] Obtain a new wheat ear subdivision binary graph, calculate the number of connected domains and center points in the new wheat ear subdivision binary graph, and form a center point array;
[0219] Calculate the grayscale value of the corresponding point in the center point array in the main grayscale image of the wheat ear, and remove the center point that does not meet the requirements near the wheat awn by determining the difference between the center grayscale value and the surrounding grayscale value, and form a new center point array with the processed center points and save it;
[0220] The new center point array is mapped back to the single wheat ear image and drawn into the single wheat ear image to obtain the grain positioning details of the single wheat ear. The grains of the wheat ear are counted based on the positioning details to obtain the number of grains in the wheat ear.
[0221] Embodiment 4:
[0222] In one embodiment, a wheat grain counting and measuring device based on grayscale value comparison is provided, and the wheat grain counting and measuring device based on grayscale value comparison can be a server or a mobile terminal. The wheat grain counting and measuring device based on grayscale value comparison includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor of the wheat grain counting and measuring device based on grayscale value comparison is used to provide computing and control capabilities. The memory of the wheat grain counting and measuring device based on grayscale value comparison includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database stores all data of the wheat grain counting and measuring device based on grayscale value comparison. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a method for measuring wheat grain counting based on grayscale value comparison is implemented.
[0223] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0224] It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as methods, devices, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0225] The present invention is described with reference to the flowcharts and / or block diagrams of the method, terminal device (system), and computer program product according to the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0226] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0227] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0228] It should be noted that:
[0229] The "one embodiment" or "embodiment" mentioned in the specification means that the specific features, structures or characteristics described in conjunction with the embodiment are included in at least one embodiment of the present invention. Therefore, the phrases "one embodiment" or "embodiment" appearing in various places throughout the specification do not necessarily refer to the same embodiment.
[0230] In addition, it should be noted that the shapes and names of the parts and components of the specific embodiments described in this specification may be different. Any equivalent or simple changes made based on the structure, features and principles described in the patent concept of the present invention are included in the protection scope of the patent of the present invention. The technicians in the technical field of the present invention can make various modifications or supplements to the specific embodiments described or replace them in a similar manner, as long as they do not deviate from the structure of the present invention or exceed the scope defined by the claims, they should all fall within the protection scope of the present invention.
Claims
1. A wheat grain counting measurement method based on gray value comparison, characterized in that: The following steps are involved: Acquire a single wheat ear image and separate the main wheat ear image; Preprocessing the wheat ear main image to obtain a first wheat ear contour line, a second wheat ear contour line and a center line, and performing a second preprocessing based on the first wheat ear contour line, the second wheat ear contour line and the center line to obtain a first wheat ear grayscale image and a second wheat ear grayscale image and a first wheat ear binarization image and a second wheat ear binarization image; The grains of the first wheat ear are subdivided based on the first wheat ear grayscale image and the first wheat ear binary image, and the grains of the second wheat ear are subdivided based on the second wheat ear grayscale image and the second wheat ear binary image, and the subdivided grains are summarized to obtain a new wheat ear subdivided binary image; Based on the new wheat ear segmentation binary image, the grain location details of a single wheat ear are obtained, and then the grains of the wheat ear are counted; The preprocessing of the wheat ear main image to obtain the first wheat ear contour line, the second wheat ear contour line and the center line, and the second preprocessing based on the first wheat ear contour line, the second wheat ear contour line and the center line to obtain the first wheat ear grayscale image and the second wheat ear grayscale image and the first wheat ear binarization image and the second wheat ear binarization image, specifically includes the following steps: Separate the wheat ear main body brightness channel image based on the wheat ear main body image; Binarization is performed on the wheat ear main body brightness channel image to obtain the contour lines and center line on both sides of the wheat ear main body, and the contour lines on both sides of the wheat ear main body are the first wheat ear contour line and the second wheat ear contour line; Keeping the center line unchanged and shortening the distances from the first contour line and the second contour line to the center line respectively, to obtain a first adjusted contour line and a second adjusted contour line; The first adjustment contour line and the center line as well as the second adjustment contour line and the center line are connected end to end and filled internally to obtain a first binary region image and a second binary region image; The main brightness channel image of the wheat ear is processed to obtain a main grayscale image of the wheat ear, and then an adaptive binarization process is performed to obtain a main binary image of the wheat ear; The first binary region image and the second binary region image are respectively used as masks and operated with the wheat ear main body grayscale image to obtain the first wheat ear grayscale image and the second wheat ear grayscale image, and the first binary region image and the second binary region image are respectively used as masks and operated with the wheat ear main body binary image to obtain the first wheat ear binary image and the second wheat ear binary image; Wherein, obtaining the new wheat ear segmentation binary image comprises the following steps: Performing a second preprocessing on the first wheat ear binary image, the second wheat ear binary image, the first wheat ear grayscale image, and the second wheat ear grayscale image to obtain a first wheat ear subdivision binary image and a second wheat ear subdivision binary image; The first wheat ear segmentation binary image and the second wheat ear segmentation binary image are summed to obtain a wheat ear segmentation binary image; The first contour line and the second contour line are connected end to end and processed to obtain a wheat ear main area map; The wheat ear main area map is used as a mask to perform operations on the wheat ear subdivision binary map to obtain a new wheat ear subdivision binary map.
2. The wheat grain counting measurement method based on gray value comparison according to claim 1, characterized in that: Get a single wheat ear image and separate the main wheat ear image, specifically: The single wheat ear image is obtained based on a black background plate; The single wheat ear image is binarized, and the lower wheat stalk part and the upper wheat awn part are removed according to the length characteristics to obtain the main image of the wheat ear.
3. The wheat grain counting measurement method based on gray value comparison according to claim 1, characterized in that: The specific steps of obtaining the first wheat ear segmentation binary image and the second wheat ear segmentation binary image are as follows: Based on the first wheat ear grayscale image, a line connecting each point on the center line and a direction line with an inclination angle within a range of 50-80 degrees in the direction of the wheat awn are obtained to form a line segment set; According to the first wheat ear binary image, the width of the first wheat ear along the center line at each tilt angle is obtained; according to the first wheat ear grayscale image and the first wheat ear binary image, the grayscale mean of the first wheat ear at each tilt angle is calculated to form a grayscale mean array; According to the grayscale difference between the grain of the first ear of wheat and the gap, a series of minimum value points and maximum value points are obtained by traversing the grayscale mean array and forming a minimum value array and a maximum value array; Based on the first wheat ear binary image and the center line, the line segment set, the minimum value of the minimum value array and the maximum value of the maximum value array, the maximum width of the first wheat ear on the direction line of the first wheat ear binary image is calculated, so as to obtain the first wheat ear subdivision binary image; Based on the second wheat ear grayscale image, a line segment set is formed by obtaining the connecting line of each point on the center line and the direction line with an inclination angle within the range of 50-80 degrees in the direction of the wheat ear; According to the second wheat ear binarization image, the width of the second wheat ear along the center line at each tilt angle is obtained; according to the second wheat ear grayscale image and the second wheat ear binarization image, the grayscale mean of the second wheat ear at each tilt angle is calculated to form a grayscale mean array; According to the grayscale difference between the grain of the second ear of wheat and the gap, a series of minimum value points and maximum value points are obtained by traversing the grayscale mean array and forming a second minimum value array and a second maximum value array; Based on the second wheat ear binary image and the center line, the line segment set, the minimum value of the second minimum value array and the maximum value of the second maximum value array, the maximum width of the second wheat ear on the direction line of the second wheat ear binary image is calculated to obtain the second wheat ear subdivision binary image.
4. A wheat grain counting measurement method based on gray value comparison according to claim 3, characterized in that: The method of counting the grains of wheat ears based on the ear-grain positioning details of the new wheat ear subdivision binary image comprises the following steps: Obtain a new wheat ear subdivision binary graph, calculate the number of connected domains and center points in the new wheat ear subdivision binary graph, and form a center point array; Calculate the grayscale value of the corresponding point in the center point array in the main grayscale image of the wheat ear, and remove the center point that does not meet the requirements near the wheat awn by determining the difference between the center grayscale value and the surrounding grayscale value, and form a new center point array with the processed center points and save it; The new center point array is mapped back to the single wheat ear image and drawn into the single wheat ear image to obtain the grain positioning details of the single wheat ear. The grains of the wheat ear are counted based on the positioning details to obtain the number of grains in the wheat ear.
5. A wheat grain counting and measurement system based on gray value comparison, characterized in that: It includes an image acquisition module, a first processing module, a second processing module and a positioning and counting module; The image acquisition module is used to acquire a single wheat ear image and separate the wheat ear main body image; The first processing module preprocesses the wheat ear main image to obtain a first wheat ear outline, a second wheat ear outline and a center line, and performs a second preprocessing based on the first wheat ear outline, the second wheat ear outline and the center line to obtain a first wheat ear grayscale image and a second wheat ear grayscale image and a first wheat ear binarization image and a second wheat ear binarization image; The second processing module subdivides the grains of the first wheat ear based on the first wheat ear grayscale image and the first wheat ear binary image, and subdivides and summarizes the grains of the second wheat ear based on the second wheat ear grayscale image and the second wheat ear binary image, to obtain a new wheat ear subdivision binary image; The positioning and counting module obtains the grain positioning details of a single wheat ear based on the new wheat ear segmentation binary image, and then counts the grains of the wheat ear; The first processing module is configured to: Separate the wheat ear main body brightness channel image based on the wheat ear main body image; Binarization is performed on the wheat ear main body brightness channel image to obtain the contour lines and center line on both sides of the wheat ear main body, and the contour lines on both sides of the wheat ear main body are the first wheat ear contour line and the second wheat ear contour line; Smoothing the first wheat ear contour line and the second wheat ear contour line to obtain a first contour line and a second contour line; Keeping the center line unchanged and shortening the distances from the first contour line and the second contour line to the center line respectively, to obtain a first adjusted contour line and a second adjusted contour line; The first adjustment contour line and the center line as well as the second adjustment contour line and the center line are connected end to end and filled internally to obtain a first binary region image and a second binary region image; The main brightness channel image of the wheat ear is processed to obtain a main grayscale image of the wheat ear, and then an adaptive binarization process is performed to obtain a main binary image of the wheat ear; The first binary region image and the second binary region image are respectively used as masks and operated with the wheat ear main body grayscale image to obtain the first wheat ear grayscale image and the second wheat ear grayscale image, and the first binary region image and the second binary region image are respectively used as masks and operated with the wheat ear main body binary image to obtain the first wheat ear binary image and the second wheat ear binary image; Wherein, obtaining the new wheat ear segmentation binary image comprises the following steps: Performing a second preprocessing on the first wheat ear binary image, the second wheat ear binary image, the first wheat ear grayscale image, and the second wheat ear grayscale image to obtain a first wheat ear subdivision binary image and a second wheat ear subdivision binary image; The first wheat ear segmentation binary image and the second wheat ear segmentation binary image are summed to obtain a wheat ear segmentation binary image; The first contour line and the second contour line are connected end to end and processed to obtain a wheat ear main area map; The wheat ear main area map is used as a mask to perform operations on the wheat ear subdivision binary map to obtain a new wheat ear subdivision binary map.
6. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.
7. A wheat grain counting and measuring device based on gray value comparison, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Method for extracting wheatear morphological parameters
CN101944231A
Method for measuring ear length and ear number of multiple wheat plants based on image processing
CN111724354A