A CT image-based paddy defect recognition and counting method
Patent Information
- Application Number
- CN202610968804.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-01
- Publication Date
- 2026-09-15
- Estimated Expiration
- 2046-07-01
AI Technical Summary
[0005]本发明提供一种基于CT图像的稻谷缺陷识别与计数方法,旨在解决二维单独检测稻谷缺陷识别和统计不准的问题
[0034]1. This invention uses 3D instance segmentation results as a spatial constraint benchmark, fusing 2D defect candidates scattered across different slices into 3D defect entities, and statistically analyzing them on a per-grain-of-rice basis. This ensures that the defect grain count accurately reflects the actual condition of the rice grains, fundamentally solving the statistical deficiencies of 2D standalone detection. Through a three-level screening mechanism—eliminating false candidate defects, optimizing trajectory consistency, and cross-instance splitting and redistribution—it effectively corrects the systematic errors of inaccurate single-layer segmentation leading to attribute jumps and incorrect two-choice selections, significantly improving the accuracy of the attribution relationship between defects and rice grain instances.
Smart Images

Figure CN122530196B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of non-destructive testing technology for grains, and in particular to a method for identifying and counting defects in rice grains based on CT images. Background Technology
[0002] Rice defects (such as insect infestation, mold, and cracks) can seriously affect rice quality, storage safety, and economic value. Therefore, accurate detection of rice defects is a core link in the entire chain of rice acquisition, storage, and processing. Traditional rice defect detection relies on manual screening, which is inefficient, highly subjective, and unable to identify hidden internal defects, making it difficult to meet the needs of large-scale and precise industry operations.
[0003] With the development of non-destructive testing (NDT) technology, X-ray computed tomography (CT) technology, with its advantages of strong penetration, high resolution, and non-destructive testing, can acquire cross-sectional images and three-dimensional structural information of rice grains, enabling visualization of internal defects. Currently, CT technology is gradually upgrading towards miniaturization and high speed, driving the transformation of rice grain inspection towards intelligence. However, existing rice grain CT defect identification technologies still suffer from problems such as insufficient accuracy, low efficiency, and inadequate utilization of three-dimensional features, making it difficult to balance detection accuracy and real-time performance, thus hindering their widespread application in large-scale rice grain inspection.
[0004] Current rice CT defect identification technologies mainly revolve around individual detection based on two-dimensional tomographic images. Two-dimensional individual detection methods typically label and identify defects independently for each CT slice, which has fundamental limitations in statistical analysis based on three-dimensional individuals. Since each rice grain spans dozens to hundreds of consecutive slices in a CT scan, two-dimensional methods can only output detection results on a slice-by-slice basis, lacking cross-slice correlation and tracking mechanisms. This makes it difficult to accurately determine whether defect areas on different slices belong to the same physical defect when statistically analyzing the internal defects of a single rice grain, easily leading to double counting or undercounting. For example, a curved crack inside a grain may appear as multiple discontinuous line segments on multiple slices; the two-dimensional model may misclassify them as multiple independent defects, resulting in a severely inflated defect count. Conversely, if the crack signal is weak in individual slices, it may be missed, leading to an undercount. Summary of the Invention
[0005] This invention provides a method for identifying and counting defects in rice grains based on CT images, aiming to solve the problem of inaccurate identification and statistical analysis of defects in rice grains detected by two-dimensional standalone methods.
[0006] The technical solution adopted by the present invention to solve the above-mentioned technical problems is as follows:
[0007] A method for identifying and counting defects in rice grains based on CT images includes the following steps:
[0008] Step 1: Obtain CT three-dimensional volume data of rice samples, perform defect detection on each two-dimensional CT slice in the three-dimensional volume data, and obtain two-dimensional defect candidate information;
[0009] Step 2: Process the CT 3D volume data to segment out the 3D instance of each rice grain, and obtain the 3D instance segmentation result;
[0010] Step 3: Based on the three-dimensional instance segmentation results, the two-dimensional defect candidate information is associated and fused between slices to determine the rice three-dimensional instance to which each two-dimensional defect candidate belongs, and the two-dimensional defect candidates on different slices belonging to the same rice three-dimensional instance are integrated into the three-dimensional defect entities of the corresponding rice grains.
[0011] Step 4: Determine the number of defective rice grains, the total number of rice grains, and the three-dimensional spatial location and defect category of each defective rice grain based on the integrated three-dimensional defect entities.
[0012] Furthermore, in step 1, a single-channel input deep learning target detection model is used for defect detection, and the first convolutional layer of the deep learning target detection model is used to receive single-channel CT grayscale image input.
[0013] Furthermore, in step 2, a label-controlled 3D watershed algorithm is used to obtain the 3D instance segmentation results of rice grains. The watershed label is the set of grain center trajectory points on the 2D slice and the set of local maxima of the 3D distance transformation.
[0014] Furthermore, the method for generating the set of particle center trajectory points on the two-dimensional slice is as follows:
[0015] A two-dimensional distance transformation is performed on the foreground region of a two-dimensional CT slice, and the local maxima of the distance transformation are extracted as candidate points for the particle center of the corresponding slice.
[0016] The candidate points of the particle center in adjacent slices are matched, and the points that meet the matching conditions are associated to form a three-dimensional center trajectory. The matching condition is that the planar distance between two points on adjacent slices does not exceed a preset maximum allowable displacement threshold.
[0017] All trajectory points on the three-dimensional central trajectory are included in the watershed marker set.
[0018] Furthermore, the method for generating the local maxima set of the three-dimensional distance transformation is as follows:
[0019] Perform a three-dimensional Euclidean distance transformation on the foreground region of the CT three-dimensional volume data, and calculate the distance from each voxel to the foreground boundary;
[0020] Local maxima points of the distance transformation are extracted and minimum spacing constraints are applied to obtain a set of local maxima points of the three-dimensional distance transformation. Points in the set of local maxima points are then included in the watershed marker set.
[0021] Furthermore, step 3 includes: removing false candidate defects belonging to the background, uniformly assigning candidate defects on the same trajectory to the rice instance with the highest support through trajectory consistency optimization, splitting candidate defects spanning multiple instances and assigning them separately, finally determining the rice 3D instance to which each 2D defect candidate belongs, and integrating 2D defect candidates on different slices belonging to the same rice 3D instance into the corresponding rice grain 3D defect entity.
[0022] Furthermore, the process of eliminating false candidate defects belonging to the background includes: for each two-dimensional defect candidate, calculating the percentage of pixels within its candidate defect region that belong to the background class in the three-dimensional instance segmentation result. ,like If the value exceeds the set threshold, the corresponding defect candidate is eliminated; where, For the first Zhang slice on the first The percentage of background pixels within each candidate defect For the first Zhang slice on the first A pixel region of candidate defects, For instance labels of voxels in the 3D instance segmentation results, For indicator functions, This indicates that the voxel belongs to the background.
[0023] Furthermore, the step of uniformly assigning candidate defects on the same trajectory to the rice instance with the highest support through trajectory consistency optimization includes:
[0024] Multiple two-dimensional defect candidates belonging to the same rice grain and having positional continuity on different slices are associated to form a two-dimensional trajectory: In the formula, For the first in the trajectory One defect candidate. This represents the total number of candidate defects contained in the trajectory;
[0025] For each 3D instance of rice Calculate the two-dimensional trajectory Support for the corresponding rice grain classification instances: In the formula, For trajectory Support for the j-th rice instance For the first The weight of each candidate defect, This represents the percentage of pixels belonging to the j-th rice instance within the candidate defect; where the weight... Take the detection confidence level With attribution credibility The combination is: ;
[0026] Example of determining the final assignment of a two-dimensional trajectory: And all two-dimensional defect candidates on the entire two-dimensional trajectory are reassigned to the corresponding instances, where, This means selecting the rice instance with the highest support among all rice instances. This represents the total number of rice instances.
[0027] Furthermore, the step of splitting and assigning candidate defects across multiple instances includes:
[0028] For the Zhang slice on the first A set of pixel regions for candidate defects If two distinct 3D instances of rice exist, calculate the set of pixel regions. With each instance Intersection area , In the formula, Indicates the first The slice belongs to the first The set of all pixels of a rice grain instance. Labels representing three-dimensional voxels;
[0029] For instances where the area of the intersection region is not less than the preset minimum area, the intersection region is taken as a new candidate defect, and the candidate defect is assigned to the rice instance corresponding to the intersection region.
[0030] Furthermore, in step 4, the defect category determination includes: summing up the detection confidence of all defect candidates contained in the two-dimensional trajectory according to the defect category, and the defect category with the largest sum is the defect category of the three-dimensional defect entity corresponding to the trajectory.
[0031] Determining the number of defective rice grains includes: taking the number of rice grain instances that belong to at least one two-dimensional trajectory as the number of defective rice grains;
[0032] The determination of the total number of rice grains includes: taking the number of rice grain instances in the 3D instance segmentation results that have a voxel count not less than a preset voxel count threshold as the total number of rice grains.
[0033] The beneficial effects of this invention are:
[0034] 1. This invention uses 3D instance segmentation results as a spatial constraint benchmark, fusing 2D defect candidates scattered across different slices into 3D defect entities, and statistically analyzing them on a per-grain-of-rice basis. This ensures that the defect grain count accurately reflects the actual condition of the rice grains, fundamentally solving the statistical deficiencies of 2D standalone detection. Through a three-level screening mechanism—eliminating false candidate defects, optimizing trajectory consistency, and cross-instance splitting and redistribution—it effectively corrects the systematic errors of inaccurate single-layer segmentation leading to attribute jumps and incorrect two-choice selections, significantly improving the accuracy of the attribution relationship between defects and rice grain instances.
[0035] 2. This invention eliminates the need for costly 3D surface mesh reconstruction. It obtains 3D defect entities through lightweight interlayer fusion between 2D detection results and 3D instance segmentation results, significantly reducing computational complexity and processing time, and is adaptable to the real-time requirements of rice batch detection scenarios.
[0036] 3. This invention can output the number of defective rice grains, the total number of rice grains, and the three-dimensional spatial location and defect category of each defective rice grain. Based on this, core quality parameters such as crack rate, mold rate, and chalkiness rate can be calculated, providing multi-dimensional quantitative data support for rice quality assessment and grading decisions. Attached Figure Description
[0037] Figure 1 This is a flowchart of a method for identifying and counting defects in rice based on CT images, as described in this invention.
[0038] Figure 2 For the design of the inspection container and CT image slicing;
[0039] Figure 3 The results of two-dimensional slice defect detection in rice grains. Detailed Implementation
[0040] In existing technologies, rice defect detection is mainly processed layer by layer on two-dimensional slices. It lacks continuity modeling and three-dimensional consistency fusion of defects between adjacent slices, which can easily lead to the same defect being counted repeatedly, missed due to fragmentation, or having an unstable category in different slices. It is difficult to achieve reliable identification and accurate counting of defects in three-dimensional solids.
[0041] Based on this, this invention first utilizes a deep learning model at the 2D CT slice level for high-sensitivity defect detection, capturing all suspicious defect signals. Then, by fusing 3D distance transformation with a 2D particle center trajectory-controlled 3D watershed algorithm, it achieves accurate individual segmentation and counting of adhered rice grains. Finally, using the 3D instance segmentation results as spatial constraints, strategies such as background false candidates removal, inter-layer voting consistency optimization based on trajectory support, and cross-instance candidate defect splitting and redistribution are employed to accurately associate and assign the 2D defect detection results scattered across different slices to the corresponding 3D rice grain individuals, thereby integrating the 2D projection information into a complete 3D defect entity. This invention fundamentally solves the problem of duplicate and missed counting caused by the inability of traditional 2D slice-based detection to distinguish between the same physical defect across slices and different independent defects. Furthermore, it eliminates the need for complete 3D surface reconstruction, ensuring both high accuracy and detection efficiency, and achieving non-destructive, accurate, and rapid identification and counting of internal defects in rice grains.
[0042] The present invention will now be described in further detail with reference to the accompanying drawings. It should be noted that these specific embodiments are merely illustrative of the invention and do not constitute a limitation on the scope of protection of the invention.
[0043] like Figure 1 As shown, the present invention provides a method for identifying and counting defects in rice based on CT images, which includes the following steps.
[0044] Step 1: Obtain candidate information for two-dimensional defects in rice samples
[0045] The purpose of this step is to detect defects in CT slices without sacrificing the original image resolution. The first layer of the YOLOv11 model is modified to have a single-channel input to match the characteristics of CT grayscale images and avoid computational redundancy. During the inference phase, a block prediction and stitching strategy is employed to maintain the original resolution and avoid missing minute defects due to scaling interpolation. During the training phase, data augmentation strategies such as random cropping, contrast perturbation, and noise injection are used to improve the model's generalization ability and comprehensively provide reliable two-dimensional defect candidate information for subsequent three-dimensional correlation.
[0046] Specifically, step 1 includes:
[0047] First, CT images of rice samples were acquired. For example... Figure 2 As shown, in this embodiment, a cylindrical container is used to load different types of mixed rice as scanning samples, with each sample containing thousands of rice grains. Then, CT scans and reconstructions are performed to obtain three-dimensional volumetric data. ;in, and These are the height and width of a single slice image, respectively. Indicates the number of slices. The three-dimensional volumetric data was obtained from X-ray CT scans and contains continuously stacked two-dimensional tomographic slices along the z-axis. ,in The first one in the formula Represents all rows in the 3D volume data, the second one. This represents all columns in the three-dimensional volume data.
[0048] Construct a dataset of rice defect annotations. After obtaining CT slice images, extract the data from the slice sequence. The sample set is constructed by selecting slices containing defects, and the defects are labeled with bounding boxes and categories. For the first... A slice, whose labeled set is denoted as: In the formula, , representing the k-th slice One candidate defect (( , and These represent the k-th slice and their respective digits. (coordinates of the center point, width, and height of the detection box corresponding to each candidate defect) As a defect category, The total number of defect categories. This represents the total number of defects in the slice.
[0049] Preprocessing of the rice defect annotation dataset. To reduce grayscale distribution drift caused by differences in different scanning batches, reconstruction parameters, and material density, while preserving the original spatial resolution and fine defect texture information, preprocessing was performed on each CT slice. First, z-score standardization is performed, then 8-bit quantization is performed, and no spatial scaling is performed throughout the process.
[0050] The specific process is as follows: For the first Zhang slice pixel set Calculate the mean with standard deviation : , In the formula, , To prevent the stable term from being divided by zero;
[0051] Pixels are standardized based on mean and standard deviation: In the formula, For the first Coordinates on the slice The normalized value of the pixel;
[0052] Meanwhile, to prevent extreme values from crowding out the dynamic range of quantization, the standardized results are truncated to a fixed interval. ( (Using an empirical threshold, such as 2, 3, or determined by quantiles), we get: In the formula, This is a truncation function used to restrict input values to a fixed range. Inside;
[0053] Then linearly mapped to And quantized to uint8 (an unsigned 8-bit integer): In the formula, This represents the final 8-bit grayscale value output.
[0054] A deep learning object detection model is trained based on a preprocessed rice defect annotation dataset. In this invention, a single-channel input deep learning object detection model is used for defect detection. The first convolutional layer of the deep learning object detection model is used to receive a single-channel CT grayscale image input.
[0055] Specifically, this embodiment uses the YOLOv11 model. The training settings for CT grayscale slices are as follows:
[0056] (1) Random cropping training
[0057] To improve batch training efficiency and small-objective learning performance without scaling the entire image, the preprocessed original slices... Randomly crop the blocks to obtain the training blocks: In the formula, To extract from the original slice The training sub-blocks obtained by cropping. This represents the starting coordinates of the cropped area in the vertical direction (row direction). This represents the starting coordinates of the cropped area in the horizontal (column) direction. For cutting dimensions, and express and From 0 The values are randomly and uniformly selected from the given range. During the trimming process, the coordinates of the labeled candidate defects are simultaneously transformed and truncated to ensure consistent supervision.
[0058] (2) Modification of single-channel input structure
[0059] To avoid redundancy and feature bias caused by copying grayscale images to 3 channels, and to improve the effective representation of low-contrast defects, the first layer convolution of YOLOv11 was changed from three-channel input to single-channel input to match CT grayscale imaging.
[0060] Specifically, let the first layer convolution weights be... for: In the formula, Indicates the size of the convolution kernel. Input the number of channels. Number of output channels;
[0061] In this embodiment, let First layer output for: In the formula, This represents the activation function. For the input training sub-block, This refers to the bias term of the first convolutional layer;
[0062] (3) Data augmentation strategy
[0063] The input obtained during the training phase is clipped Apply combinatorial enhancement, denoted as the enhancement operator. ,but: In the formula, For the data-augmented training sub-block images, The annotation information is after data augmentation. This refers to the original labeled information. Specifically, data augmentation includes:
[0064] Contrast perturbation: In the formula, To enhance the image in coordinates Pixel value at that location, For contrast ratio, This is for brightness offset;
[0065] Noise injection (simulated imaging noise): In the formula, Indicates coordinates Random noise values added at the location, This indicates that the random noise values follow a mean of 0 and a variance of . The normal distribution;
[0066] Affine transformation: In the formula, Affine transformation matrix, The original coordinate vector contains coordinates. and homogeneous coordinates, where The scaling factor in is ; This indicates that the scaling factor follows a mean of 0.8 and a variance of... Uniform distribution;
[0067] All of the above enhancement operations perform isomorphic transformations to update the bounding box coordinates, thereby maintaining label consistency.
[0068] In terms of model prediction settings, to avoid loss of defect details due to scaling the entire high-resolution slice to a fixed input size, a block-prediction-stitching strategy is adopted during the inference stage. New slices are then... Divide into several overlapping or non-overlapping sub-blocks:
[0069] , In the formula, For from the first The set of all sub-blocks divided by Zhang's slice. For the first The total number of sub-blocks divided by Zhang slice, For the first The sub-block indexes of the slice. For the first The coordinate region of each sub-block on the original image This represents array indexing operations, indicating the retrieval of coordinate regions. Pixels within the range.
[0070] The detection results are obtained by inputting each sub-block into the model. Then map the candidate defects in the sub-block coordinate system back to the original image coordinate system: In the formula, Indicates the first Zhang slice, number Sub-block, the first The coordinates of each candidate defect in the original image coordinate system This represents the coordinates of the same candidate defect in the sub-block coordinate system. This represents the offset of the top-left corner of the sub-block within the entire image. This represents a coordinate translation mapping.
[0071] Finally, the predicted sub-blocks are merged, and non-maximum suppression (NMS) is performed on the entire graph to obtain the final output of the slice: In the formula, For the first The final detection result of the slice after nonmaximum suppression; This represents the nonmaximum suppression algorithm. Indicates the first The detection results of all sub-blocks on the slice are collected and merged; Indicates the first Zhang slice, number The set of detection results for each sub-block; This represents the confidence threshold; candidate defects below this value are discarded directly. This represents the crossover ratio threshold, used to determine whether two candidate defects are the same target.
[0072] This stitching inference method achieves full-image detection while maintaining the original resolution, reducing the risk of missed detections caused by scaling interpolation for minor defects.
[0073] The final output of the The final set of detection results for the slices is as follows: In the formula, Indicates the first Zhang slice on the first The center coordinates of each candidate defect ( With width and high , The target confidence level for the corresponding candidate defect. This represents the category probability vector for the corresponding candidate defects. Indicates the first The number of predicted targets on the slice. Detection results are as follows: Figure 3 As shown.
[0074] Step 2: Obtain 3D instance segmentation results
[0075] In this step, candidate particle center points are first extracted from each slice using a two-dimensional distance transformation. Based on the spatial proximity of center points between adjacent slices, these points are associated with a three-dimensional center trajectory that runs through the entire rice grain, forming a set of particle center trajectory points on the two-dimensional slices. Simultaneously, a three-dimensional Euclidean distance transformation is performed on the foreground region in the three-dimensional volume data space to extract local maxima points of the distance field and apply minimum spacing constraints, obtaining a set of local maxima points of the three-dimensional distance transformation. These two point sets are then fused to generate an accurate and robust watershed label set, which guides the label-controlled three-dimensional watershed algorithm to segment adhered rice grains. This fusion strategy utilizes the inter-layer continuity of the two-dimensional center trajectory to ensure that each rice grain receives at least one internal label, and uses three-dimensional distance peaks to complete areas with severe adhesion or broken trajectories, effectively suppressing the oversegmentation and undersegmentation problems common in traditional watershed algorithms. Finally, the label of each voxel and the accurate count of all rice grains are output, providing an accurate spatial constraint benchmark for subsequent cross-level association of defects and rice grains. Specifically, step 2 includes:
[0076] 2.1 Remove container background interference
[0077] Because the sample is placed in a cylindrical container, the container exhibits a ring-like structure on each slice. Constructing a ring template. (parameter (Representing the center and inner and outer radii), template matching is performed on each slice to estimate container parameters. : In the formula, Indicates the parameter calculation Make the function The value is the largest. No. Zhang slice and circular template The normalized cross-correlation value; where the normalized cross-correlation value is... for: ;
[0078] Generate a mask for the effective area inside the container from the estimated circle parameters (the mask can be appropriately shrunk to avoid leaving residue on the container wall). ); In the formula, For the first Coordinates on the slice The mask value at that location, This is an indicator function; the value is 1 if the condition inside the parentheses is true and 0 if it is false. For the first The row coordinates of the center of the container on the slice. For the first The column coordinates of the center of the container on the slice. For the first The radius of the container on the slice. This is the inward shrinkage amount, used to shrink inward to remove residue from the container wall;
[0079] Stacking to form a 3D ROI mask And obtain the volume data after removing the container background. : In the formula, This represents element-wise multiplication;
[0080] To enhance interlayer stability, Apply smoothing constraints along the slice direction to obtain the smoothed container parameters. : In the formula, For the first The original container parameters of the slice, To smooth the window radius, This is the offset, and its value ranges from... arrive ;
[0081] This helps to suppress ROI jitter caused by matching errors in individual slices.
[0082] 2.2 Separation of Adhesive Rice Individuals
[0083] The overall shape of a single rice grain is approximately convex. If multiple rice grains come into contact and adhere together, they typically correspond to multiple "central peaks" within the three-dimensional foreground connected volume. This method constructs watershed terrain through three-dimensional distance transformation and introduces the inter-layer trajectory of the center point of the two-dimensional slice to stabilize the generation of three-dimensional markers, thereby reducing over-segmentation and under-segmentation. The specific process is as follows:
[0084] (1) Obtaining the foreground binary mask
[0085] right Threshold segmentation is performed to obtain a binary mask of candidate rice grains foreground, and gray values greater than or equal to the threshold are selected. Voxels with a value greater than the threshold are labeled as foreground (rice grains), and voxels with a value less than the threshold are labeled as background. , In the formula, Foreground binary mask in voxels The value at that location is either 0 or 1. This is an indicator function; the value is 1 if the condition inside the parentheses is true and 0 if it is false. Volume data after removing container background in voxels grayscale value at that location The threshold value set;
[0086] And on Three-dimensional morphological denoising and hole repair were performed to obtain .
[0087] (2) Three-dimensional distance transformation and watershed topography
[0088] Calculate the three-dimensional Euclidean distance transformation: In the formula, voxels The three-dimensional Euclidean distance to the foreground boundary. express The boundary of a voxel is the set of voxels at the junction of the foreground and background. The greater the distance from the nearest foreground boundary, the stronger the... The closer it is to the center of the particle; the smaller the distance, the better. The closer to the surface of the rice grain, the more likely the watershed topography is to have a negative distance. : .
[0089] (3) Generation of three-dimensional markers guided by two-dimensional center trajectory
[0090] To improve the stability of seed localization under adhesion conditions, this method first extracts "slice center candidates" on each slice, then performs inter-layer correlation to generate center trajectories, and finally elevates the trajectory points to three-dimensional watershed markers.
[0091] a. Slice-level center candidate extraction
[0092] For the Foreground of a slice Calculate the two-dimensional distance transformation: In the formula, For the first Coordinates on the slice The two-dimensional distance value to the foreground boundary. Let it be a distance function. Indicates the first The set of boundaries of the foreground region on a slice;
[0093] exist Extracting local maxima sets as candidate particle centers for this layer : In the formula, the threshold Used to remove weak peaks caused by noise.
[0094] b. Center trajectory generation
[0095] The center candidates of adjacent slices are matched to form a three-dimensional center trajectory. In the formula, This represents the total number of points contained in the track. Taking nearest neighbor threshold matching as an example, for... and Define matching cost : ,when It is considered that they can be related, among which The maximum allowable displacement (reflecting the smooth change in the center of the rice grain across adjacent layers). The trajectory is obtained through layer-by-layer correlation: , Index for the number of trajectory lines, This is the starting slice number for the trajectory. This is the end slice number of the trajectory.
[0096] c. Three-dimensional distance peak fusion
[0097] Use the trajectory points obtained in the previous step as a set of 3D markers: Simultaneously, to utilize convex priors and further suppress oversegmentation, in the three-dimensional range field... Extracting the set of local maxima from above: In the formula, A 3D height threshold is set to filter weak peaks with excessively small distance values, and then a minimum spacing constraint (related to the rice grain scale) is applied: In the formula, For the first The coordinates of the local maxima points are eventually merged to obtain the labeled set. For the first The coordinates of the local maxima points are eventually merged to obtain the labeled set. Assuming a minimum spacing constraint, the final fusion yields the following tag set: This fusion labeling strategy utilizes the interlayer continuity at the center of the two-dimensional section to ensure that "each rice grain has at least one label", and uses three-dimensional distance peaks to complete areas with severe adhesion or trajectory breakage, thereby reducing undersegmentation and oversegmentation.
[0098] (4) Label-controlled 3D watershed segmentation
[0099] In foreground mask Under restrictions, with To mark on the terrain Perform a 3D watershed operation to obtain 3D instance segmentation results. : In the formula, This represents a watershed algorithm with tag control. This is a watershed topography, i.e., a negative distance transformation. , This represents the initial set of marker points for the watershed algorithm. This indicates that the specified segmentation region is limited to the foreground mask area, resulting in instance segmentation results without category information: ; where 0 represents the background, For different individual rice grains.
[0100] (5) Rice count
[0101] Extract the first A set of voxels of rice grains: In the formula, For the first The set of all voxels contained in a rice instance, and the minimum voxel count threshold. After removing noisy connected components, the total number of rice grains is as follows: The output includes: segmentation results. Instance collection With total count This is used to constrain the 3D fusion of defects to be attributed to a specific rice instance, thereby improving the accuracy of subsequent defect identification and counting.
[0102] Step 3: Determine the 3D instance of rice to which each 2D defect candidate belongs.
[0103] This step, based on the 3D instance segmentation results, establishes a cross-level association mechanism between 2D defect detection and 3D rice grain individuals, accurately assigning candidate defects scattered across slices to their corresponding rice grains, forming complete 3D defect entities. Specifically, it includes three steps: first, removing false candidate defects with excessive background coverage; second, using trajectory-level weighted voting to uniformly assign candidate defects belonging to the same defect on consecutive slices to the rice grain instance with the highest support; and third, splitting candidate defects spanning multiple rice grains by instance and assigning them separately. This cross-level association strategy, based on removing false candidate defects, trajectory consistency, and splitting / reassigning, fundamentally eliminates ambiguity and segmentation error propagation in correcting 2D→3D association under rice grain instance constraints. Specifically, it includes the following steps:
[0104] 3.1 Eliminating spurious candidate defects
[0105] Suppose for the th Zhang slice on the first The set of pixel regions of candidate defects is Calculate the proportion of rice grain instances j within the candidate defect to obtain the pixel proportion belonging to a specific rice grain within the candidate defect: In the formula, For the first Zhang slice on the first Within the candidate defect, belonging to the first... Pixel percentage of each rice grain instance For the first Zhang slice on the first A pixel region of candidate defects, This is an indicator function.
[0106] Define the background proportion: In the formula, Indicates the first Zhang slice on the first The percentage of background pixels within each candidate defect This indicates that the voxel belongs to the background;
[0107] Set a threshold ,like If the candidate is not found to be trustworthy (often a false positive due to background / container issues), it can be discarded or downgraded. In this embodiment, .
[0108] 3.2 Trajectory Consistency Association
[0109] Adjacent two-dimensional candidates are associated as trajectories based on category continuity. For the same trajectory Seeking trajectory-level unique rice instances through weighted support. To maximize the overall support of the trajectory on this instance, in the formula, For the first One defect candidate. The trajectory includes the total number of subsequent candidate defects.
[0110] Weighted support is defined as: ; For trajectory Support for the j-th rice instance For the first The weight of each candidate defect, This represents the percentage of pixels belonging to the j-th rice instance within the candidate defect. The weights are... Take the detection confidence level With attribution credibility The combination is: .
[0111] The final instance assigned to the trajectory is the one with the highest support. In the formula, For trajectory The final rice instance number, This indicates the search for the maximum value; even if multiple instances appear within a certain layer of candidate defects ( (Dispersed) As long as the trajectory clearly falls on the same grain of rice in most layers, it will eventually be "voted" back to the correct instance, thereby correcting the affiliation jumps and ambiguities caused by inaccurate single-layer segmentation.
[0112] For each candidate in the trajectory If its current hard affiliation Track attribution Inconsistent, and the candidate defect is related to... If the proportion is not zero, then it will be redistributed to : The target rice grain within the candidate defect. If the proportion is greater than or equal to the set threshold, then the defect is assigned to... Otherwise, retain the original maximum proportion of the defect on the slice of this layer, where, For the redistributed number Zhang slice on the first The final assignment instance of each candidate defect. For this candidate defect to belong to The pixel ratio of this rice grain example This is set as the minimum acceptable percentage (e.g., 0.1~0.2) to avoid forcibly assigning completely disjoint candidate defects. This is the largest rice grain instance on this slice.
[0113] 3.3 Split and Redistribution
[0114] When a candidate defect indeed spans multiple instances, it is split based on the intersection of the instances. If a candidate defect satisfies the condition of significant coexistence of multiple instances at this layer, i.e.: If , then splitting occurs; in the formula, This is a preset critical ratio. Candidate defects are defined in instances. Intersection area : ;right Instance generation of sub-candidate defects ( (Minimum area threshold in two dimensions) In the formula, This represents finding the minimum bounding rectangle and forming new candidate defects. Its affiliation is fixed as an instance. The split candidate defects are then subjected to trajectory association and trajectory-level attribution optimization. This corrects the systematic error of incorrectly selecting one of two options due to cross-instance defects.
[0115] For each trajectory Ultimate Attribution Instance The spatial location of the three-dimensional defective rice grains is output using the trajectory's three-dimensional center. (Available trajectory 3D center): In the formula, This represents the total number of candidate defects contained in the trajectory.
[0116] Step 4: Determine the number of defective rice grains, the total number of rice grains, and the three-dimensional spatial location and defect category of each defective rice grain.
[0117] The detection confidence scores of all defect candidates included in the 2D trajectory are summed according to defect category. The defect category with the highest sum is the defect category of the 3D defect entity corresponding to the trajectory. Final defect category for: The number of rice grain instances belonging to at least one two-dimensional trajectory is taken as the number of defective rice grains. for: The total number of rice grain instances in the 3D instance segmentation result with a voxel count not less than a preset voxel count threshold is taken as the total number of rice grains. Specifically, the total number of all rice grains is the number of segmented instances plus the minimum voxel threshold. filter): .
[0118] Based on the statistically analyzed number of defective rice grains, defect categories, and total number of rice grains, multi-dimensional quality indicators of rice are calculated, including core quality parameters such as crack rate, diseased rate, chalkiness rate, germination rate, and mold rate. The rate of each indicator is calculated as: (Number of defective rice grains / Total number of rice grains) × 100%. Detailed information such as the three-dimensional location, size, and category of each defect can also be output, providing data support for rice quality grading and screening.
Claims
1. A method for identifying and counting defects in rice grains based on CT images, characterized in that, Includes the following steps: Step 1: Obtain CT three-dimensional volume data of rice samples, perform defect detection on each two-dimensional CT slice in the three-dimensional volume data, and obtain two-dimensional defect candidate information; Step 2: Process the CT 3D volume data to segment out the 3D instance of each rice grain, and obtain the 3D instance segmentation result; Step 3: Based on the 3D instance segmentation results, the 2D defect candidate information is correlated and fused between slices to determine the rice 3D instance to which each 2D defect candidate belongs, and the 2D defect candidates on different slices belonging to the same rice 3D instance are integrated into the corresponding rice grain 3D defect entities; specifically, this includes: removing false candidate defects belonging to the background, uniformly assigning candidate defects on the same trajectory to the rice instance with the highest support through trajectory consistency optimization, and splitting and assigning candidate defects that span multiple instances respectively, finally determining the rice 3D instance to which each 2D defect candidate belongs, and integrating the 2D defect candidates on different slices belonging to the same rice 3D instance into the corresponding rice grain 3D defect entities; Step 4: Determine the number of defective rice grains, the total number of rice grains, and the three-dimensional spatial location and defect category of each defective rice grain based on the integrated three-dimensional defect entities.
2. The method for identifying and counting rice defects based on CT images according to claim 1, characterized in that, In step 1, a single-channel input deep learning target detection model is used for defect detection. The first convolutional layer of the deep learning target detection model is used to receive a single-channel CT grayscale image input.
3. The method for identifying and counting rice defects based on CT images according to claim 1, characterized in that, In step 2, the label-controlled 3D watershed algorithm is used to obtain the 3D instance segmentation result of rice grains. The watershed label is the set of grain center trajectory points on the 2D slice and the set of local maxima of the 3D distance transformation.
4. The method for identifying and counting rice defects based on CT images according to claim 3, characterized in that, The method for generating the particle center trajectory point set on the two-dimensional slice is as follows: A two-dimensional distance transformation is performed on the foreground region of a two-dimensional CT slice, and the local maxima of the distance transformation are extracted as candidate points for the particle center of the corresponding slice. The candidate points of the particle center in adjacent slices are matched, and the points that meet the matching conditions are associated to form a three-dimensional center trajectory. The matching condition is that the planar distance between two points on adjacent slices does not exceed a preset maximum allowable displacement threshold. All trajectory points on the three-dimensional central trajectory are included in the watershed marker set.
5. The method for identifying and counting rice defects based on CT images according to claim 3, characterized in that, The method for generating the local maxima set of the three-dimensional distance transformation is as follows: Perform a three-dimensional Euclidean distance transformation on the foreground region of the CT three-dimensional volume data, and calculate the distance from each voxel to the foreground boundary; Local maxima points of the distance transformation are extracted and minimum spacing constraints are applied to obtain a set of local maxima points of the three-dimensional distance transformation. Points in the set of local maxima points are then included in the watershed marker set.
6. The method for identifying and counting rice defects based on CT images according to claim 1, characterized in that, The process of eliminating false candidate defects belonging to the background includes: for each two-dimensional defect candidate, calculating the percentage of pixels within its candidate defect region that belong to the background class in the three-dimensional instance segmentation result. ,like If the value exceeds the set threshold, the corresponding defect candidate is eliminated; where, For the first Zhang slice on the first The percentage of background pixels within each candidate defect For the first Zhang slice on the first A pixel region of candidate defects, For instance labels of voxels in the 3D instance segmentation results, For indicator functions, This indicates that the voxel belongs to the background.
7. The method for identifying and counting rice defects based on CT images according to claim 1, characterized in that, The method of uniformly classifying candidate defects on the same trajectory to the rice instance with the highest support through trajectory consistency optimization includes: Multiple two-dimensional defect candidates belonging to the same rice grain and having positional continuity on different slices are associated to form a two-dimensional trajectory: In the formula, For the first in the trajectory One defect candidate This represents the total number of candidate defects contained in the trajectory. For each 3D instance of rice Calculate the two-dimensional trajectory Support for the corresponding rice grain classification instances: In the formula, For trajectory Support for the j-th rice instance For the first The weight of each candidate defect, This represents the percentage of pixels belonging to the j-th rice instance within the candidate defect; where the weight... Take the detection confidence level With attribution credibility The combination is: ; Example of determining the final assignment of a two-dimensional trajectory: And all two-dimensional defect candidates on the entire two-dimensional trajectory are reassigned to the corresponding instances, where, This means selecting the rice instance with the highest support among all rice instances. This represents the total number of rice instances.
8. The method for identifying and counting rice defects based on CT images according to claim 1, characterized in that, The process of splitting and assigning candidate defects across multiple instances includes: For the Zhang slice on the first A set of pixel regions for candidate defects If two distinct 3D instances of rice exist, calculate the set of pixel regions. With each instance Intersection area , In the formula, Indicates the first The slice belongs to the first The set of all pixels of a rice grain instance. Labels representing three-dimensional voxels; For instances where the area of the intersection region is not less than the preset minimum area, the intersection region is taken as a new candidate defect, and the candidate defect is assigned to the rice instance corresponding to the intersection region.
9. A method for identifying and counting defects in rice grains based on CT images according to claim 7, characterized in that, In step 4, the defect category determination includes: summing up the detection confidence of all defect candidates contained in the two-dimensional trajectory according to the defect category, and the defect category with the largest sum is the defect category of the three-dimensional defect entity corresponding to the trajectory. Determining the number of defective rice grains includes: taking the number of rice grain instances that belong to at least one two-dimensional trajectory as the number of defective rice grains; The determination of the total number of rice grains includes: taking the number of rice grain instances in the 3D instance segmentation results that have a voxel count not less than a preset voxel count threshold as the total number of rice grains.
Citation Information
Patent Citations
Three-dimensional visual defect detection method based on CT
CN112967280A
Dynamic defect real-time detection system based on deep learning
CN121120526A