Defect judgment method and system for medicinal decoction piece image analysis
By performing grayscale processing and contour recognition on images of medicinal decoction pieces, setting detection dot matrix templates, constructing a feature retrieval structure, and analyzing dot matrix difference features, the problem of automating the detection of defects in medicinal decoction pieces was solved, achieving efficient and accurate defect determination.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- ANGUO SHENHAO PHARM CO LTD
- Filing Date
- 2026-03-23
- Publication Date
- 2026-06-19
AI Technical Summary
In existing technologies, the detection of defects in medicinal decoction pieces relies on manual identification, which is inefficient and lacks standardized criteria, making it difficult to adapt to the biodiversity of medicinal decoction pieces and leading to missed or false detections.
By performing grayscale processing on the images of medicinal herbs, identifying the contour lines and calculating the center, setting detection dot matrix templates, constructing a dot matrix record feature retrieval structure, analyzing dot matrix difference features, and using a defect probability recognition library to determine defects.
It has achieved efficient, accurate and automated detection of defects in medicinal herbs, improving the retrieval efficiency and defect identification accuracy of quality inspection.
Smart Images

Figure CN122243967A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of quality inspection technology for medicinal decoction pieces, and in particular to a method and system for determining defects in medicinal decoction pieces based on image analysis. Background Technology
[0002] As a core component of the traditional Chinese medicine industry, the quality of processed medicinal materials directly impacts clinical efficacy and safety. During processing, transportation, and packaging, these materials are highly susceptible to damage such as edge breakage, central cracking, or missing parts due to mechanical impact, improper cutting techniques, or storage conditions. These defects not only affect the appearance of the medicinal materials but may also lead to the loss of active ingredients or failure to meet pharmacopoeia specifications. Therefore, rigorous defect detection before packaging is a crucial step in quality control.
[0003] Currently, defect detection of medicinal slices mainly relies on manual visual inspection. However, manual inspection is not only labor-intensive and inefficient, but also susceptible to subjective experience and visual fatigue, making it difficult to standardize inspection criteria and easily leading to missed or false detections. With the development of machine vision technology, methods have been attempted to use computer image processing technology for automatic detection. However, due to the high biodiversity of medicinal slices, slices of the same variety can vary significantly in outline shape, internal texture (such as "chrysanthemum heart" or "brocade-like pattern"), and color. This "homogeneous heterogeneity" characteristic makes traditional detection algorithms based on fixed geometric templates or simple histogram statistics difficult to adapt. Summary of the Invention
[0004] The purpose of this invention is to provide a highly efficient and accurate method and system for judging defects in medicinal herbs.
[0005] This invention discloses a method for defect judgment in the image analysis of medicinal decoction pieces, including: Step S100: The selected standard medicinal slice images are processed into grayscale to obtain standard medicinal slice grayscale images. Contour lines are identified in the standard medicinal slice grayscale images, and the center of the medicinal slices is calculated based on the contour lines. Step S200: Set a detection dot matrix template for each standard drug decoction piece grayscale image, analyze the grayscale value of each detection point in the detection dot matrix template, and associate and record it with the detection point to obtain the standard detection dot matrix record. Step S300: Perform feature classification on the standard detection dot matrix records to form a dot matrix record feature retrieval structure, and use the index to call the standard detection dot matrix records; Step S400: Process the real-time image of the medicinal slices, and analyze the gray values of the detection points using the detection dot matrix template to obtain the real-time detection dot matrix record. Then, use the dot matrix record feature retrieval structure to search the real-time dot matrix record, find the corresponding standard detection dot matrix record, and record it as the valid standard dot matrix record. Analyze the dot matrix difference features between the real-time detection dot matrix record and the valid standard dot matrix record, and determine whether the medicinal slices are defective based on the dot matrix difference features.
[0006] In some embodiments disclosed in this invention, the method for setting the detection dot matrix template includes: Step S201: Based on the center of the medicinal slices, construct detection circles step by step, with several detection points evenly set on each detection circle.
[0007] In some embodiments disclosed in this invention, the method for feature classification of standard detection dot matrix records includes: Step S301: Calculate the gray variance of the gray value of each detection circle in the standard detection dot matrix record, and construct an initial classification topology structure by using the gray variance of the detection circle at each level as the classification condition. Step S302: Using the detection circle as the baseline and the detection point as the origin, construct a grayscale scale line. Based on the grayscale value corresponding to the detection point, mark the corresponding grayscale mapping point on the grayscale scale line. Perform linear fitting on all the grayscale mapping points corresponding to the detection circle to obtain a circular grayscale fluctuation line. Step S303: Perform cross-level joint feature analysis on the circular gray-scale fluctuation lines corresponding to the circular lines detected at each level. This includes calibrating the texture mutation blocks of the standard medicinal slices, mapping the texture mutation blocks onto the gray-scale image of the standard medicinal slices with circular gray-scale fluctuation lines, recording the corresponding circular gray-scale fluctuation line segments within the texture mutation blocks, and recording the average curvature, curvature variation variance, and average gray-scale value of the circular gray-scale fluctuation line segments of the texture mutation blocks. Step S304: Construct a secondary classification topology based on the average curvature, curvature variation variance, and average gray value of each circular grayscale fluctuation segment in the texture mutation block, and combine it with the initial classification topology to obtain the dot matrix record feature retrieval structure.
[0008] In some embodiments disclosed in this invention, the method for analyzing the dot matrix difference characteristics between real-time detection dot matrix records and valid standard dot matrix records includes: Step S401: Compare the gray values of the detection points in the real-time detection dot matrix record and the valid standard dot matrix record to determine the gray value difference for each detection point. Step S402: If the difference in grayscale values is greater than or equal to a preset value, the corresponding detection point is marked as a detection point of interest. The positional approximation of the detection points of interest is analyzed, including constructing a scanning window and translating the scanning window in the detection point matrix. The detection points of interest that fall into the scanning window at the same time are associated, and finally the correlation matrix of the detection points of interest that are associated with each other is obtained. Step S403: The shape and grayscale value difference of the associated dot matrix that need to be focused on are identified as dot matrix difference features.
[0009] In some embodiments disclosed in this invention, the method for determining whether medicinal slices have defects based on dot matrix difference features includes: Step S404: Construct a defect probability identification library for the relevant matrix points to be concerned, and use the defect probability identification library to perform defect probability analysis on the relevant matrix points to be concerned. If the defect probability is greater than or equal to a preset value, it is determined that the medicinal slices are defective.
[0010] In some embodiments disclosed in this invention, the method for constructing a defect probability identification library includes: Step S4041: Approximately classify the obtained dot matrix difference features to obtain several dot matrix difference feature groups. Based on the corresponding actual defect records, mark the dot matrix difference features in the dot matrix difference feature groups as defective. Calculate the defect ratio of dot matrix difference features with defect markings in the dot matrix difference feature groups and identify the defect ratio as the defect probability of the dot matrix difference feature groups. The methods for approximating and classifying the difference features of the dot matrix include: The shape approximation parameter analysis is performed on the shape of the related points that need to be focused on, and the gray value difference approximation parameter analysis is performed on the gray value difference between the related points that need to be focused on. The shape approximation parameter and the gray value difference approximation parameter are obtained respectively. Based on the shape approximation parameter and the gray value difference approximation parameter, it is determined whether the point difference features should be classified into one category.
[0011] In some embodiments disclosed in this invention, a method for performing shape approximation parametric analysis on the shape between related point lattices of interest includes: Step S4042: Perform several relative rotations and translations on the related point matrix that needs attention, and calculate the overlapping area between the related point matrix that needs attention each time. Calculate the percentage of the overlapping area relative to the mapped area of each related point matrix that needs attention, and select the lower percentage of overlapping area as the reference percentage of overlapping area. Analyze the reference percentage of overlapping area corresponding to each of the several rotations and translations, and select the rotation and translation with the highest percentage of reference overlapping area as the alignment and overlap method of the related point matrix that needs attention. Step S4043: The proportion of the reference overlapping area is identified as the shape approximation parameter.
[0012] In some embodiments disclosed in this invention, a method for performing approximate parametric analysis of grayscale value differences between related point matrices of interest includes: Step S4043: After aligning and overlapping the relevant points, compare and analyze the gray value difference of each relative detection point, calculate the secondary difference between the two, and determine whether the secondary difference is greater than or equal to the preset value. If so, mark the corresponding detection point as a gray value difference point. Step S4043: Randomly select several grayscale difference analysis blocks from the relevant point matrix, and statistically analyze the difference point ratio of grayscale difference points in the blocks to determine the average difference point ratio of all grayscale difference analysis blocks, and recognize the average difference point ratio as an approximate parameter of grayscale value difference.
[0013] In some embodiments disclosed in this invention, a defect judgment system for image analysis of medicinal decoction pieces is also disclosed, including: The first module is used to perform grayscale processing on the selected standard medicinal slice images to obtain standard medicinal slice grayscale images, and to perform contour line recognition on the standard medicinal slice grayscale images, and calculate the center of the medicinal slice based on the contour lines. The second module is used to set a detection dot matrix template for each standard drug decoction piece grayscale image, analyze the grayscale value of each detection point in the detection dot matrix template, and associate and record it with the detection point to obtain the standard detection dot matrix record. The third module is used to classify the standard test dot matrix records by feature and form a dot matrix record feature retrieval structure to retrieve the standard test dot matrix records by index. The fourth module processes real-time images of medicinal herbs and analyzes the grayscale values of detection points using a detection dot matrix template to obtain real-time detection dot matrix records. It then uses a dot matrix record feature retrieval structure to search for the real-time dot matrix records, find the corresponding standard detection dot matrix records, and record them as valid standard dot matrix records. The module analyzes the dot matrix difference features between the real-time detection dot matrix records and the valid standard dot matrix records, and determines whether the medicinal herbs are defective based on these dot matrix difference features.
[0014] This invention discloses a method and system for defect assessment in medicinal herb image analysis, belonging to the field of medicinal herb quality inspection technology. The method involves first performing grayscale conversion and contour recognition on standard medicinal herb images to calculate and establish the center of the herb; then, based on this center, a detection dot matrix template is set, and the grayscale values of each detection point are collected and associated to generate a standard detection dot matrix record; further, a dot matrix feature retrieval structure is constructed through feature classification to achieve efficient indexing of the standard records. In the real-time detection stage, the same dot matrix grayscale analysis is performed on the image to be tested to obtain a real-time record. The retrieval structure is used to quickly match the corresponding valid standard record, and by analyzing the dot matrix differences between the two, the defect status of the medicinal herb is accurately determined. This invention solves the problem of automated comparison caused by the natural shape differences of medicinal herb pieces, significantly improving the retrieval efficiency and defect identification accuracy of traditional Chinese medicine herb quality inspection.
[0015] The technical solution of the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. Attached Figure Description
[0016] Figure 1 This is a flowchart illustrating the steps of the method for determining defects in images of medicinal decoction pieces disclosed in this application. Detailed Implementation
[0017] The technical solution of the present invention will be further described below with reference to the accompanying drawings and embodiments.
[0018] The technical solution of the present invention will be clearly and completely described below with reference to the accompanying drawings and specific embodiments. It should be understood that the preferred embodiments described herein are only for illustration and explanation of the present invention and should not be construed as limiting the scope of protection of the present invention. Those skilled in the art can make some non-essential improvements and adjustments based on the following content of the present invention. In the present invention, unless otherwise expressly specified and limited, the technical terms used in the present invention should have the ordinary meaning understood by those skilled in the art.
[0019] Example: This invention discloses a method for defect judgment in the image analysis of medicinal decoction pieces, see reference. Figure 1 ,include: Step S100: The selected standard medicinal slice images are converted to grayscale to obtain standard medicinal slice grayscale images. The grayscale images of standard medicinal slices are then used for contour line recognition, and the center of the medicinal slices is calculated based on the contour lines.
[0020] The core of this step lies in spatial normalization. Since natural medicinal slices (such as astragalus and licorice) may experience light and shadow interference and random positioning during photography, the three-channel color information is first compressed into single-channel brightness information through grayscale processing, thereby eliminating color cast interference and reducing computational load. Next, an edge detection operator (such as the Canny operator) is used for contour recognition to pinpoint the physical boundaries of the slices. Most importantly, the centroid or geometric center of the slice is calculated using image moments or circumcircle algorithms. This center point serves as the origin of the coordinate system for all subsequent sampling operations, ensuring that even if the slices are translated on the conveyor belt, the system can accurately align them based on their relative positions. This is known in computer vision as "affine transformation invariance processing."
[0021] Step S200: Set a detection dot matrix template for each standard drug slice grayscale image, analyze the grayscale value of each detection point in the detection dot matrix template, and associate and record it with the detection point to obtain the standard detection dot matrix record.
[0022] The essence of this step is to transform continuous image signals into discrete numerical feature vectors. Directly comparing the entire image would lead to computational overload and extremely low fault tolerance due to the massive number of pixels. By setting a "detection dot matrix template," the system essentially draws a specific arrangement of detection pins (which can be concentric circles or a grid) on a transparent film, collecting only the grayscale values at these specific coordinate points. This sampling method condenses a complex image into a set of digital records associated with "grayscale values and positions." For example, for a pill with an annual ring texture, the dot matrix can capture the brightness fluctuations radiating outwards from the center. This "point-for-surface" method not only greatly compresses the data volume but also establishes a unified digital "metric" for subsequent standard comparisons by fixing the sampling points.
[0023] Step S300: Perform feature classification on the standard detection dot matrix records to form a dot matrix record feature retrieval structure, and use the index to call the standard detection dot matrix records.
[0024] This step aims to solve the problem of efficient matching of heterogeneous data. Since there are a large number of standard samples in the drug library, a "brute-force search" is not feasible during real-time detection. The system will classify these standard dot matrix records by features (such as grayscale variance, fluctuation line curvature, etc., as mentioned in the preceding claims), constructing a topological structure similar to a "dictionary index".
[0025] Step S400: Process the real-time image of the medicinal slices, and analyze the gray values of the detection points using the detection dot matrix template to obtain the real-time detection dot matrix record. Then, use the dot matrix record feature retrieval structure to search the real-time dot matrix record, find the corresponding standard detection dot matrix record, and record it as the valid standard dot matrix record. Analyze the dot matrix difference features between the real-time detection dot matrix record and the valid standard dot matrix record, and determine whether the medicinal slices are defective based on the dot matrix difference features.
[0026] This is the decision-making output stage of the entire solution. The system first uses the index established by S300 to quickly find the most matching "valid standard dot matrix record," and then performs a point-by-point "subtraction" operation between the real-time acquired dot matrix and the standard dot matrix. This dot matrix difference characteristic can intuitively reflect the inconsistency in brightness distribution between the two: if the standard value of a certain area should be high brightness (solid medicinal material tissue), while the real-time value is low brightness (gap or void), a significant difference will occur. Based on the spatial distribution of these difference points (whether they are in patches, whether the shape is abnormal) and the preset probability recognition library, the system can eliminate the small fluctuations caused by natural textures, accurately determine whether the difference belongs to a physical defect, and finally give the instruction of meeting the standard or rejection.
[0027] In some embodiments disclosed in this invention, the method for setting the detection dot matrix template includes: Step S201: Based on the center of the medicinal slices, construct detection circles step by step, with several detection points evenly set on each detection circle.
[0028] In some embodiments disclosed in this invention, the method for feature classification of standard detection dot matrix records includes: Step S301: Calculate the grayscale variance of the grayscale value of each detection circle in the standard detection dot matrix record, and construct an initial classification topology structure by using the grayscale variance of the detection circle at each level as the classification condition.
[0029] The principle behind this step is to use variance, a statistical term, to describe the activity level of texture. In image processing, a larger variance usually means that the area has drastic changes in brightness (such as the dense radial texture inside a pill), while a smaller variance represents smoothness. By calculating the gray-level variance of each layer of concentric "detection circles," the system is essentially extracting a "coarse fingerprint" of the pill.
[0030] Step S302: Using the detection circle as the baseline and the detection point as the origin, construct a grayscale scale line. Based on the grayscale value corresponding to the detection point, mark the corresponding grayscale mapping point on the grayscale scale line. Perform linear fitting on all the grayscale mapping points corresponding to the detection circle to obtain a circular grayscale fluctuation line.
[0031] The essence of this step is to unfold the two-dimensional circular spatial information into a one-dimensional signal waveform. Mathematically, this is similar to the conversion from polar coordinates to rectangular coordinates: using the detection circle as a reference (horizontal axis), the grayscale values of each point are projected onto the vertical axis as the height, and a linear fit is performed to obtain an undulating "electrocardiogram"—a circular grayscale wave line. The ingenuity of this transformation lies in converting the complex ring-shaped texture of the pill into a continuous function that is easy to perform mathematical analysis. For example, if there is a dark ring of cambium in the center of the pill, it will appear as a distinct trough on the wave line. This lays the data foundation for subsequent extraction of fine geometric features (such as curvature).
[0032] Step S303: Perform cross-level joint feature analysis on the circular gray-scale fluctuation lines corresponding to the circular lines detected at each level. This includes calibrating the texture mutation blocks of the standard medicinal slices, mapping the texture mutation blocks onto the gray-scale image of the standard medicinal slices with circular gray-scale fluctuation lines, recording the corresponding circular gray-scale fluctuation line segments within the texture mutation blocks, and recording the average curvature, curvature variation variance, and average gray-scale value of the circular gray-scale fluctuation line segments of the texture mutation blocks.
[0033] This step involves a deeper analysis of local geometric descriptors. Since key identifying features of medicinal herbs are typically concentrated at points of abrupt texture changes (such as the "chrysanthemum heart" of ginseng or the cambium layer of astragalus), the system identifies these "texture abrupt change blocks" and maps them back to undulating lines to extract specific line segments. Next, the average curvature (reflecting the steepness of texture changes), the variance of curvature changes (reflecting the rhythmicity of texture changes), and the average grayscale of these line segments are calculated. This not only records "there is texture here," but also precisely records "how the texture turns and undulates here." This cross-level joint analysis effectively captures the unique growth logic of biological tissues, thereby distinguishing between natural textures and artificial defects.
[0034] Step S304: Construct a secondary classification topology based on the average curvature, curvature variation variance, and average gray value of each circular grayscale fluctuation segment in the texture mutation block, and combine it with the initial classification topology to obtain the dot matrix record feature retrieval structure.
[0035] This step is the final assembly of the feature structure, based on multi-level index optimization. A "secondary classification topology" is constructed using the refined geometric features (curvature, variance, etc.) extracted in step S303, and nested under the "initial topology" of step S301. The resulting dot matrix record feature retrieval structure is essentially a multi-dimensional decision tree or inverted index. When real-time acquired tablet images enter the system, the algorithm first locates the approximate range using macroscopic variance, and then performs precise matching using microscopic curvature features. This hierarchical and progressive retrieval method ensures both the speed of finding "valid standard records" in a large-scale standard database and the recognition accuracy when faced with highly similar tablet samples.
[0036] In some embodiments disclosed in this invention, the method for analyzing the dot matrix difference characteristics between real-time detection dot matrix records and valid standard dot matrix records includes: Step S401: Compare the gray values of the detection points in the real-time detection dot matrix record and the valid standard dot matrix record to determine the gray value difference for each detection point.
[0037] Step S402: If the difference in grayscale values is greater than or equal to a preset value, the corresponding detection point is marked as a detection point of interest. The positional approximation of the detection points of interest is analyzed, including constructing a scanning window and translating the scanning window in the detection point matrix. The detection points of interest that fall into the scanning window at the same time are associated, and finally the correlation matrix of the detection points of interest that are associated with each other is obtained.
[0038] Step S403: The shape and grayscale value difference of the associated dot matrix that need to be focused on are identified as dot matrix difference features.
[0039] In some embodiments disclosed in this invention, the method for determining whether medicinal slices have defects based on dot matrix difference features includes: Step S404: Construct a defect probability identification library for the relevant matrix points to be concerned, and use the defect probability identification library to perform defect probability analysis on the relevant matrix points to be concerned. If the defect probability is greater than or equal to a preset value, it is determined that the medicinal slices are defective.
[0040] In some embodiments disclosed in this invention, the method for constructing a defect probability identification library includes: Step S4041: Approximately classify the obtained dot matrix difference features to obtain several dot matrix difference feature groups. Based on the corresponding actual defect records, mark the dot matrix difference features in the dot matrix difference feature groups as defective. Calculate the defect ratio of dot matrix difference features with defect markings in the dot matrix difference feature groups and identify the defect ratio as the defect probability of the dot matrix difference feature groups.
[0041] The principle behind this step is to establish an empirical correlation model based on historical big data. In industrial inspection, not all image differences represent true defects (some may be minor adjustments to lighting or natural textures). The system collects a large number of known "difference features" and compares them with manually labeled "actual results" to calculate the mathematical probability that each type of feature will evolve into a true defect.
[0042] The methods for approximating and classifying the difference features of the dot matrix include: The shape approximation parameter analysis is performed on the shape of the related points that need to be focused on, and the gray value difference approximation parameter analysis is performed on the gray value difference between the related points that need to be focused on. The shape approximation parameter and the gray value difference approximation parameter are obtained respectively. Based on the shape approximation parameter and the gray value difference approximation parameter, it is determined whether the point difference features should be classified into one category.
[0043] When building the identification database, determining whether two differing features belong to the "same type of lesion" is crucial. The system employs a multi-dimensional similarity evaluation principle: first, shape approximation parameter analysis, which focuses on the geometric contours of the differing regions (whether it's a long, narrow crack, a circular wormhole, or an irregular bump); second, grayscale value difference approximation parameter analysis, which focuses on the "degree of damage," i.e., how much the real-time brightness deviates from the standard brightness (whether it's slightly darkened or completely black). Through cross-comparison of these two dimensions, the system can accurately "bind" and classify tens of thousands of differing features. Only when two features are similar in shape and similar in color change are they classified into the same group, thus ensuring the purity and reference value of each group of data in the probability database.
[0044] In some embodiments disclosed in this invention, a method for performing shape approximation parametric analysis on the shape between related point lattices of interest includes: Step S4042: Perform several relative rotations and translations on the related point matrix that needs attention, and calculate the overlapping area between the related point matrix that needs attention each time. Calculate the percentage of the overlapping area relative to the mapped area of each related point matrix that needs attention, and select the lower percentage of overlapping area as the reference percentage of overlapping area. Analyze the reference percentage of overlapping area corresponding to each of the several rotations and translations, and select the rotation and translation with the highest percentage of reference overlapping area as the alignment and overlap method of the related point matrix that needs attention. Step S4043: The proportion of the reference overlapping area is identified as the shape approximation parameter.
[0045] In some embodiments disclosed in this invention, a method for performing approximate parametric analysis of grayscale value differences between related point matrices of interest includes: Step S4043: After aligning and overlapping the relevant points, compare and analyze the gray value difference of each relative detection point, calculate the secondary difference between the two, and determine whether the secondary difference is greater than or equal to the preset value. If so, mark the corresponding detection point as a gray value difference point. Step S4043: Randomly select several grayscale difference analysis blocks from the relevant point matrix, and statistically analyze the difference point ratio of grayscale difference points in the blocks to determine the average difference point ratio of all grayscale difference analysis blocks, and recognize the average difference point ratio as an approximate parameter of grayscale value difference.
[0046] The principle behind this step is to use statistical sampling to assess overall similarity. To avoid individual noise points interfering with the judgment, the system does not directly use the entire image data, but instead randomly selects multiple "analysis blocks" in the dot matrix (similar to randomly sampling a few communities on a map). By calculating the proportion of "grayscale distinguishing points" within these blocks and taking the average, the system is essentially extracting a density parameter. This "average distinguishing point proportion" can intuitively reflect the "relatedness" of two defective samples in terms of grayscale features: the lower the proportion, the more similar the color change patterns of the two samples are, and the greater the probability that they belong to the same type of defect. This method based on local sampling and resynthesis greatly improves the robustness of the algorithm, ensuring that even when the pill texture is extremely complex, the system can still accurately summarize stable defect probability features.
[0047] The classification of dot matrix difference features is determined by whether the approximate parameters of gray value difference belong to the same parameter range and whether the approximate parameters of shape belong to the same parameter range.
[0048] In some embodiments disclosed in this invention, a defect judgment system for image analysis of medicinal decoction pieces is also disclosed, including: The first module is used to perform grayscale processing on the selected standard medicinal slice images to obtain standard medicinal slice grayscale images, and to perform contour line recognition on the standard medicinal slice grayscale images, and to calculate the center of the medicinal slice based on the contour lines.
[0049] The second module is used to set a detection dot matrix template for each standard drug decoction piece grayscale image, analyze the grayscale value of each detection point in the detection dot matrix template, and associate and record it with the detection point to obtain the standard detection dot matrix record.
[0050] The third module is used to classify the standard test dot matrix records by feature and form a dot matrix record feature retrieval structure to retrieve the standard test dot matrix records by index. The fourth module processes real-time images of medicinal herbs and analyzes the grayscale values of detection points using a detection dot matrix template to obtain real-time detection dot matrix records. It then uses a dot matrix record feature retrieval structure to search for the real-time dot matrix records, find the corresponding standard detection dot matrix records, and record them as valid standard dot matrix records. The module analyzes the dot matrix difference features between the real-time detection dot matrix records and the valid standard dot matrix records, and determines whether the medicinal herbs are defective based on these dot matrix difference features.
[0051] This invention discloses a method and system for defect assessment in medicinal herb image analysis, belonging to the field of medicinal herb quality inspection technology. The method involves first performing grayscale conversion and contour recognition on standard medicinal herb images to calculate and establish the center of the herb; then, based on this center, a detection dot matrix template is set, and the grayscale values of each detection point are collected and associated to generate a standard detection dot matrix record; further, a dot matrix feature retrieval structure is constructed through feature classification to achieve efficient indexing of the standard records. In the real-time detection stage, the same dot matrix grayscale analysis is performed on the image to be tested to obtain a real-time record. The retrieval structure is used to quickly match the corresponding valid standard record, and by analyzing the dot matrix differences between the two, the defect status of the medicinal herb is accurately determined. This invention solves the problem of automated comparison caused by the natural shape differences of medicinal herb pieces, significantly improving the retrieval efficiency and defect identification accuracy of traditional Chinese medicine herb quality inspection.
[0052] Through the above description of the embodiments, those skilled in the art can clearly understand that the present invention can be implemented in hardware or by means of software plus necessary general-purpose hardware platforms. Based on this understanding, the technical solution of the present invention can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (such as a CD-ROM, USB flash drive, external hard drive, etc.) and includes several instructions to cause a computer device (such as a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments of the present invention.
[0053] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit them. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can still be made to the technical solutions of the present invention, and these modifications or equivalent substitutions cannot cause the modified technical solutions to deviate from the spirit and scope of the technical solutions of the present invention.
Claims
1. A method for determining defects in images of medicinal decoction pieces, characterized in that, include: Step S100: The selected standard medicinal slice images are processed into grayscale to obtain standard medicinal slice grayscale images. Contour lines are identified in the standard medicinal slice grayscale images, and the center of the medicinal slices is calculated based on the contour lines. Step S200: Set a detection dot matrix template for each standard drug decoction piece grayscale image, analyze the grayscale value of each detection point in the detection dot matrix template, and associate and record it with the detection point to obtain the standard detection dot matrix record. Step S300: Perform feature classification on the standard detection dot matrix records to form a dot matrix record feature retrieval structure, and use the index to call the standard detection dot matrix records; Step S400: Process the real-time image of the medicinal slices, and analyze the gray values of the detection points using the detection dot matrix template to obtain the real-time detection dot matrix record. Then, use the dot matrix record feature retrieval structure to search the real-time dot matrix record, find the corresponding standard detection dot matrix record, and record it as the valid standard dot matrix record. Analyze the dot matrix difference features between the real-time detection dot matrix record and the valid standard dot matrix record, and determine whether the medicinal slices are defective based on the dot matrix difference features.
2. The defect judgment method for image analysis of medicinal decoction pieces according to claim 1, characterized in that, Methods for setting a detection dot matrix template include: Step S201: Based on the center of the medicinal slices, construct detection circles step by step, with several detection points evenly set on each detection circle.
3. The method for defect judgment in image analysis of medicinal decoction pieces according to claim 1, characterized in that, Methods for feature classification of standard detection matrix records include: Step S301: Calculate the gray variance of the gray value of each detection circle in the standard detection dot matrix record, and construct an initial classification topology structure by using the gray variance of the detection circle at each level as the classification condition. Step S302: Using the detection circle as the baseline and the detection point as the origin, construct a grayscale scale line. Based on the grayscale value corresponding to the detection point, mark the corresponding grayscale mapping point on the grayscale scale line. Perform linear fitting on all the grayscale mapping points corresponding to the detection circle to obtain a circular grayscale fluctuation line. Step S303: Perform cross-level joint feature analysis on the circular gray-scale fluctuation lines corresponding to the circular lines detected at each level. This includes calibrating the texture mutation blocks of the standard medicinal slices, mapping the texture mutation blocks onto the gray-scale image of the standard medicinal slices with circular gray-scale fluctuation lines, recording the corresponding circular gray-scale fluctuation line segments within the texture mutation blocks, and recording the average curvature, curvature variation variance, and average gray-scale value of the circular gray-scale fluctuation line segments of the texture mutation blocks. Step S304: Construct a secondary classification topology based on the average curvature, curvature variation variance, and average gray value of each circular grayscale fluctuation segment in the texture mutation block, and combine it with the initial classification topology to obtain the dot matrix record feature retrieval structure.
4. The method for defect judgment in image analysis of medicinal decoction pieces according to claim 1, characterized in that, Methods for analyzing the dot matrix difference characteristics between real-time detection dot matrix records and valid standard dot matrix records include: Step S401: Compare the gray values of the detection points in the real-time detection dot matrix record and the valid standard dot matrix record to determine the gray value difference for each detection point. Step S402: If the difference in grayscale values is greater than or equal to a preset value, the corresponding detection point is marked as a detection point of interest. The positional approximation of the detection points of interest is analyzed, including constructing a scanning window and translating the scanning window in the detection point matrix. The detection points of interest that fall into the scanning window at the same time are associated, and finally the correlation matrix of the detection points of interest that are associated with each other is obtained. Step S403: The shape and grayscale value difference of the associated dot matrix that need to be focused on are identified as dot matrix difference features.
5. The defect judgment method for image analysis of medicinal decoction pieces according to claim 4, characterized in that, Methods for determining whether medicinal slices have defects based on dot matrix differences include: Step S404: Construct a defect probability identification library for the relevant matrix points to be concerned, and use the defect probability identification library to perform defect probability analysis on the relevant matrix points to be concerned. If the defect probability is greater than or equal to a preset value, it is determined that the medicinal slices are defective.
6. The defect judgment method for image analysis of medicinal decoction pieces according to claim 5, characterized in that, Methods for constructing a defect probability identification library include: Step S4041: Approximately classify the obtained dot matrix difference features to obtain several dot matrix difference feature groups. Based on the corresponding actual defect records, mark the dot matrix difference features in the dot matrix difference feature groups as defective. Calculate the defect ratio of dot matrix difference features with defect markings in the dot matrix difference feature groups and identify the defect ratio as the defect probability of the dot matrix difference feature groups. The methods for approximating and classifying the difference features of the dot matrix include: The shape approximation parameter analysis is performed on the shape of the related points that need to be focused on, and the gray value difference approximation parameter analysis is performed on the gray value difference between the related points that need to be focused on. The shape approximation parameter and the gray value difference approximation parameter are obtained respectively. Based on the shape approximation parameter and the gray value difference approximation parameter, it is determined whether the point difference features should be classified into one category.
7. The defect judgment method for image analysis of medicinal decoction pieces according to claim 6, characterized in that, Methods for approximate shape parametric analysis of the shapes between related points of interest include: Step S4042: Perform several relative rotations and translations on the related point matrix that needs attention, and calculate the overlapping area between the related point matrix that needs attention each time. Calculate the percentage of the overlapping area relative to the mapped area of each related point matrix that needs attention, and select the lower percentage of overlapping area as the reference percentage of overlapping area. Analyze the reference percentage of overlapping area corresponding to each of the several rotations and translations, and select the rotation and translation with the highest percentage of reference overlapping area as the alignment and overlap method of the related point matrix that needs attention. Step S4043: The proportion of the reference overlapping area is identified as the shape approximation parameter.
8. The method for defect judgment in image analysis of medicinal decoction pieces according to claim 7, characterized in that, Methods for approximate parametric analysis of grayscale value differences between relevant points include: Step S4043: After aligning and overlapping the relevant points, compare and analyze the gray value difference of each relative detection point, calculate the secondary difference between the two, and determine whether the secondary difference is greater than or equal to the preset value. If so, mark the corresponding detection point as a gray value difference point. Step S4043: Randomly select several grayscale difference analysis blocks from the relevant point matrix, and statistically analyze the difference point ratio of grayscale difference points in the blocks to determine the average difference point ratio of all grayscale difference analysis blocks, and recognize the average difference point ratio as an approximate parameter of grayscale value difference.
9. A defect judgment system for image analysis of medicinal decoction pieces, characterized in that, include: The first module is used to perform grayscale processing on the selected standard medicinal slice images to obtain standard medicinal slice grayscale images, and to perform contour line recognition on the standard medicinal slice grayscale images, and calculate the center of the medicinal slice based on the contour lines. The second module is used to set a detection dot matrix template for each standard drug decoction piece grayscale image, analyze the grayscale value of each detection point in the detection dot matrix template, and associate and record it with the detection point to obtain the standard detection dot matrix record. The third module is used to classify the standard test dot matrix records by feature and form a dot matrix record feature retrieval structure to retrieve the standard test dot matrix records by index. The fourth module processes real-time images of medicinal herbs and analyzes the grayscale values of detection points using a detection dot matrix template to obtain real-time detection dot matrix records. It then uses a dot matrix record feature retrieval structure to search for the real-time dot matrix records, find the corresponding standard detection dot matrix records, and record them as valid standard dot matrix records. The module analyzes the dot matrix difference features between the real-time detection dot matrix records and the valid standard dot matrix records, and determines whether the medicinal herbs are defective based on these dot matrix difference features.