Deep learning based method for spike counting and length-width measurement

By employing a deep learning-based rotational target detection method, utilizing the YOLO12-OBB model and STRtree algorithm, high-precision counting and length/width measurement of rice panicles were achieved. This solves the problems of low efficiency and low accuracy in existing technologies, and improves the accuracy and speed of automated detection.

CN122223441APending Publication Date: 2026-06-16UNIV OF ELECTRONICS SCI & TECH OF CHINA
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-04-27
Publication Date
2026-06-16

AI Technical Summary

Technical Problem

Existing technologies for counting grains in rice panicles and measuring their length and width suffer from low efficiency, time-consuming and labor-intensive processes, and low accuracy, especially when the panicles are densely packed or tilted, making accurate segmentation and measurement difficult.

Method used

A deep learning-based rotating target detection method is adopted, using the YOLO12-OBB model combined with the STRtree algorithm to achieve accurate positioning and high-precision counting of grains in the ear, and to obtain grain length and width information through the rotation frame parameters.

Benefits of technology

It has achieved fully automated, high-precision counting and length and width measurement of rice panicles, improving detection accuracy and calculation efficiency, and solving the problems of low efficiency and strong subjectivity in traditional methods.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122223441A_ABST
    Figure CN122223441A_ABST
Patent Text Reader

Abstract

The application discloses a kind of based on deep learning's ear grain counting and length-width measurement method, belong to target detection and image processing technical field.The method described in the application utilizes deep learning technology, combines rotation target detection and image processing algorithm, and the high-precision counting and morphological measurement of dense and inclined rice ear grain are carried out.The method described in the application realizes the full-automatic counting and length-width measurement of rice grain on ear based on deep learning, solves the problem of low efficiency and strong subjectivity of traditional method.The method described in the application uses YOLO12-OBB rotation detection model, compared with traditional horizontal frame detection, can more accurately fit the inclined grain contour, significantly improve the precision of length-width measurement.The method described in the application uses STRtree algorithm to accelerate the deduplication processing of overlapping area, compared with the intersection of all frame pairs by brute force calculation, greatly improves the running speed of algorithm when processing large-size image.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of target detection and image processing technology, specifically relating to a deep learning-based method for counting and measuring the length and width of rice spikes. It utilizes deep learning technology, combined with rotational target detection and image processing algorithms, to perform high-precision counting and morphological measurement of dense and tilted rice spikes. In particular, it employs the YOLO12-OBB model and the STRtree-accelerated nonmaximum suppression algorithm, achieving both detection accuracy and computational efficiency when processing small targets in high-resolution images. Background Technology

[0002] The number of grains per panicle and the length and width of grains are core indicators for assessing rice yield and quality. Accurately obtaining these parameters is crucial for rice breeding, phenotypic analysis, and yield prediction. Currently, panicle counting and grain length and width measurement mainly rely on manual labor, which is not only time-consuming and labor-intensive, but also extremely inefficient, and easily influenced by the subjective judgment of the measurer, leading to data errors. Furthermore, manual processing of large numbers of samples is difficult to perform quickly and non-destructively, failing to meet the needs of modern intelligent agriculture.

[0003] For grain counting, existing image processing methods often struggle to accurately segment individual targets when faced with densely packed, mutually occluding grains, leading to under- or over-counting results. For length and width measurement, since rice grains are typically tilted in their natural state, existing horizontal bounding box (HBB) detection methods cannot accurately fit the grain outline, resulting in the measured length and width including a large number of background pixels and poor measurement accuracy. Summary of the Invention

[0004] The purpose of this invention is to address the difficulty in detecting rice grains due to their dense, small size, and tilt. It provides a deep learning-based method for counting grains and measuring their length and width. By utilizing deep learning's rotating target detection technology, it achieves accurate positioning and high-precision automatic counting of grains, and directly obtains high-precision grain length and width information through the rotation frame parameters.

[0005] The technical problem addressed by this invention is solved as follows:

[0006] A deep learning-based method for counting grains in a spike and measuring its length and width includes the following steps:

[0007] Step 1, Dataset Construction and Preprocessing

[0008] The dataset contains several original images, in which all ears of grain are assigned a rotated rectangle as a label box; the original images are cropped, and there are overlapping areas between adjacent cropped sub-images;

[0009] During the image cropping process, cropping rectangles are first generated on the original image based on the size of the cropping sub-images and the overlapping area. The image in each cropping rectangle is used as a cropping sub-image. For label boxes whose center point is located within the cropping rectangle, the coordinates of the label boxes are transformed from the coordinates of the original image to the coordinates of the current cropping sub-image.

[0010] For each original image, all cropped sub-images and coordinate-transformed bounding boxes are used as sample data and labels to construct training samples; all training samples are divided into training set and validation set in an 8:2 ratio.

[0011] Step 2, Model Training

[0012] YOLO12-OBB was selected as the rotating target detection model. The training set and validation set constructed in step 1 were used to train and validate the rotating target detection model, respectively.

[0013] Step 3, Reasoning and Post-processing

[0014] The image to be measured is cropped, and the size of the cropped sub-image and the overlapping area of ​​adjacent cropped sub-images are consistent with the cropped sub-image in step 1. The cropped sub-image to be measured is input into the trained rotating target detection model. The rotating target detection model infers and outputs the ear rotation rectangles from the input cropped sub-image to be measured. The ear rotation rectangles are summarized and statistically analyzed and restored to the coordinates of the image to be measured. The number of ear rotation rectangles is counted as the number of ears of grains. The average length and width of the high-confidence ear rotation rectangles are taken as the measurement result of the length and width of the ears of grains.

[0015] Furthermore, in step 1, the size of the overlapping region... for:

[0016]

[0017] in, Original image size To cut the sub-image size, This indicates rounding down to the nearest integer.

[0018] Furthermore, in step 1, the size of the cropped sub-image is set to 720×720.

[0019] Furthermore, in step 1, the specific implementation process of converting the coordinates of the label box from the original image coordinates to the current cropping sub-image coordinates is as follows: subtract the coordinates of the upper left corner of the cropping rectangle from the coordinates of all vertices of the label box to obtain the relative coordinates of the grain label box in the cropping sub-image.

[0020] Furthermore, in step 3, the top 20% of the panicle grain rotation rectangles with the highest confidence level are selected as representative samples. The average width and average height of the panicle rotation rectangles corresponding to the selected representative samples are calculated as the average grain length and average grain width of the rice panicle of this plant.

[0021] Furthermore, in step 3, for the grain rotation rectangle of the image to be measured output by the rotating target detection model, deduplication is performed using non-maximum suppression based on the crossover ratio. The specific process is as follows:

[0022] (1) Sorting: Sort in descending order according to the confidence level of each ear of grains in the rotating rectangle;

[0023] (2) Selection: Select the rotating rectangle of the ear with the highest confidence, mark it as selected, and move it to the detection result list; use the STRtree method to search the remaining rotating rectangles of the ear to find candidate boxes that intersect with the current rotating rectangle of the ear;

[0024] (3) Calculate IOS: For each candidate box, calculate its intersection ratio with the current ear rotation rectangle. The intersection ratio IOS is expressed as: , The overlapping area, The minimum area of ​​the candidate box and the rotated rectangle of the grain spike;

[0025] (4) Comparison and elimination: Eliminate candidate boxes whose IOS with the current ear grain rotation rectangle exceeds a preset threshold;

[0026] (5) Cycling and suppression: Repeat steps (2)-(4) until all grain rotation rectangles are marked as selected, and obtain the final list of detection results.

[0027] The beneficial effects of this invention are:

[0028] The method described in this invention achieves fully automated counting and length / width measurement of rice grains on an ear of grain based on deep learning, solving the problems of low efficiency and high subjectivity in traditional methods. The method employs the YOLO12-OBB rotation detection model, which, compared to traditional horizontal box detection, can more accurately fit the contours of tilted rice grains, significantly improving the accuracy of length and width measurement. Furthermore, the method utilizes the STRtree algorithm to accelerate the deduplication of overlapping regions, greatly improving the algorithm's running speed when processing large images compared to brute-force calculation of the intersection of all box pairs. Attached Figure Description

[0029] Figure 1 This is a schematic diagram of image cropping in the method described in this invention;

[0030] Figure 2 This is a schematic diagram illustrating the overlapping areas between adjacent cropping sub-images in the method described in this invention.

[0031] Figure 3 This is a schematic diagram illustrating the calculation of the crossover ratio in the method described in this invention;

[0032] Figure 4 This is a schematic diagram of the deduplication of the rotating rectangular frame of the ear grains in the method described in this invention. Detailed Implementation

[0033] The present invention will be further described below with reference to the accompanying drawings and embodiments.

[0034] To enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions of the embodiments of the present invention will be described in detail and completely below with reference to the accompanying drawings. Obviously, the embodiments described with reference to the accompanying drawings are exemplary and intended to explain the present invention, but should not be construed as limiting the present invention.

[0035] This embodiment provides a deep learning-based method for ear grain counting and length / width measurement. Utilizing image cropping and stitching with rotational nonmaximum suppression techniques, it achieves accurate detection of densely packed small targets in high-resolution images. Specifically, it includes the following steps:

[0036] Step 1, Dataset Construction and Preprocessing

[0037] The dataset contains several original images, each with a rotated bounding box as its label. The original images are cropped, with each cropped sub-image measuring 720×720 pixels. Adjacent cropped sub-images overlap. Figure 2 As shown, to ensure appropriate overlap between adjacent subgraphs and guarantee that edge targets can be used for training, the size of the overlapping region in this embodiment is specified. for:

[0038]

[0039] in, Original image size To cut the sub-image size, This indicates rounding down to the nearest integer.

[0040] During the image cropping process, cropping rectangles are first generated on the original image based on the size and overlapping area of ​​the cropping sub-images. The image in each cropping rectangle is used as a cropping sub-image. For label boxes whose center point is located within the cropping rectangle, the coordinates of the label boxes are transformed from the coordinates of the original image to the coordinates of the current cropping sub-image.

[0041] For each original image, all cropped sub-images and coordinate-transformed label boxes are used as sample data and labels respectively to construct training samples; all training samples are divided into training set and validation set in an 8:2 ratio.

[0042] In this embodiment, the specific process of converting the coordinates of the label frame from the original image coordinates to the current cropping sub-image coordinates is as follows: subtract the coordinates of the upper left corner of the cropping rectangle from the coordinates of all vertices of the label frame to obtain the relative coordinates of the grain label frame in the cropping sub-image.

[0043] Step 2, Model Training

[0044] YOLO12-OBB was selected as the rotating target detection model, and the training set and validation set constructed in step 1 were used to train and validate the rotating target detection model, respectively.

[0045] In this embodiment, YOLO12-OBB is selected as the base network. OBB (Oriented Bounding Box) can output an angled rotating box, which, compared with the traditional horizontal box (HBB), can fit the tilted grain outline more closely and reduce the interference of background pixels, thus providing more accurate geometric parameters for subsequent length and width measurements.

[0046] Step 3, Reasoning and Post-processing

[0047] The image to be measured is cropped, with the size of the cropped sub-image set to 720×720. There are overlapping areas between adjacent cropped sub-images to avoid missing edge targets. The cropped sub-image is then input into a trained rotating target detection model. The rotating target detection model infers and outputs rotating rectangles of the ears of grain from the input cropped sub-image. The rotating rectangles of the ears of grain are summarized and statistically analyzed and restored to the coordinates of the image to be measured. The number of rotating rectangles of the ears of grain is counted as the number of ears of grain. The average length and width of the high-confidence rotating rectangles of the ears of grain are taken as the measurement result of the length and width of the ears of grain.

[0048] In this embodiment, low-confidence targets are usually obscured or have blurred edges. In order to eliminate the interference of false detection boxes, the top n highest confidence grain rotation rectangles are selected as representative samples. The average width and average height of the selected grain rotation rectangles are calculated as the average grain length and average grain width of the rice panicle. In this embodiment, n is 20%.

[0049] In this embodiment, due to overlapping cropping, grains in the overlapping region will be repeatedly detected by two adjacent sub-images, thus requiring deduplication. For the grain rotation rectangles in the image to be measured output by the rotation target detection model, deduplication is performed using non-maximum suppression based on intersection ratio (IOS). The specific process is as follows:

[0050] (1) Sorting: The rotating rectangles of each ear of grain are sorted in descending order according to their confidence level. The rotating rectangles of the ear of grain with the highest confidence level are considered to be the most likely to correctly detect the target.

[0051] (2) Selection: Select the rotating rectangle of the ear with the highest confidence from the sorted list, mark it as selected, and move it to the detection result list; use the STRtree method to search the remaining rotating rectangles of the ear to find candidate boxes that may intersect with the current rotating rectangle of the ear;

[0052] (3) Calculate IOS: For each candidate box, calculate its intersection ratio (IOS) with the current ear rotation rectangle, such as... Figure 3 As shown, the crossover ratio IOS is expressed as: , The overlapping area, The minimum area of ​​the candidate box and the rotated rectangle of the grain spike;

[0053] (4) Comparison and elimination: Eliminate candidate boxes whose IOS with the current ear grain rotation rectangle exceeds a preset threshold;

[0054] (5) Cycling and suppression: Repeat steps (2)-(4) until all grain rotation rectangles are marked as selected, and obtain the final detection result list. The deduplication effect is shown in Figure 4.

Claims

1. A method for ear grain counting and length / width measurement based on deep learning, characterized in that, Includes the following steps: Step 1, Dataset Construction and Preprocessing The dataset contains several original images, in which all ears of grain are assigned a rotated rectangle as a label box; the original images are cropped, and there are overlapping areas between adjacent cropped sub-images; During the image cropping process, cropping rectangles are first generated on the original image based on the size of the cropping sub-images and the overlapping area. The image in each cropping rectangle is used as a cropping sub-image. For label boxes whose center point is located within the cropping rectangle, the coordinates of the label boxes are transformed from the coordinates of the original image to the coordinates of the current cropping sub-image. For each original image, all cropped sub-images and coordinate-transformed bounding boxes are used as sample data and labels to construct training samples; all training samples are divided into training set and validation set in an 8:2 ratio. Step 2, Model Training YOLO12-OBB was selected as the rotating target detection model. The training set and validation set constructed in step 1 were used to train and validate the rotating target detection model, respectively. Step 3, Reasoning and Post-processing The image to be measured is cropped, and the size of the cropped sub-image and the overlapping area of ​​adjacent cropped sub-images are consistent with the cropped sub-image in step 1; the cropped sub-image to be measured is then input into the trained rotating target detection model. The rotating target detection model infers and outputs a rotating rectangle of the ear of grains from the input cropped image to be measured. The rotating rectangles of the ear of grains are summarized and statistically analyzed and restored to the coordinates of the image to be measured. The number of rotating rectangles of the ear of grains is counted as the number of ears of grains. The average length and width of the high-confidence rotating rectangles of the ear of grains are taken as the measurement result of the length and width of the ear of grains.

2. The method for ear grain counting and length / width measurement based on deep learning according to claim 1, characterized in that, In step 1, the size of the overlapping region for: in, Original image size To cut the sub-image size, This indicates rounding down to the nearest integer.

3. The method for ear grain counting and length / width measurement based on deep learning according to claim 1, characterized in that, In step 1, the size of the cropped sub-image is set to 720×720.

4. The method for ear grain counting and length / width measurement based on deep learning according to claim 1, characterized in that, In step 1, the specific process of converting the coordinates of the label box from the original image coordinates to the current cropping sub-image coordinates is as follows: subtract the coordinates of the upper left corner of the cropping rectangle from the coordinates of all vertices of the label box to obtain the relative coordinates of the grain label box in the cropping sub-image.

5. The method for ear grain counting and length / width measurement based on deep learning according to claim 1, characterized in that, In step 3, the top 20% of the panicle grain rotation rectangles with the highest confidence level are selected as representative samples. The average width and average height of the panicle rotation rectangles corresponding to the selected representative samples are calculated as the average grain length and average grain width of the rice panicle of this plant.

6. The method for ear grain counting and length / width measurement based on deep learning according to claim 1, characterized in that, In step 3, for the grain rotation rectangle of the image to be measured output by the rotating target detection model, deduplication is performed using non-maximum suppression based on the crossover ratio. The specific process is as follows: (1) Sorting: Sort in descending order according to the confidence level of each ear of grains in the rotating rectangle; (2) Selection: Select the rotating rectangle of the ear of grain with the highest confidence level, mark it as selected, and move it to the list of detection results; The STRtree method is used to search the remaining rotating rectangles of the ear of grains to find candidate boxes that intersect with the current rotating rectangle of the ear of grains. (3) Calculate IOS: For each candidate box, calculate its intersection ratio with the current ear rotation rectangle. The intersection ratio IOS is expressed as: , The overlapping area, The minimum area of ​​the candidate box and the rotated rectangle of the grain spike; (4) Comparison and elimination: Eliminate candidate boxes whose IOS with the current ear grain rotation rectangle exceeds a preset threshold; (5) Cycling and suppression: Repeat steps (2)-(4) until all grain rotation rectangles are marked as selected, and obtain the final list of detection results.