AI-based medicine quality detection method and system

By constructing the CIELAB color space and fuzzy membership matrix, and combining the aluminum foil transmissive binarized image with the topological set of the connected components of the packaging, the problem of distinguishing different risk levels in pharmaceutical quality testing in existing technologies is solved, and robust and quantitative testing of pharmaceutical liquids and packaging is achieved.

CN121883976APending Publication Date: 2026-04-17DALIAN MEDICAL UNIVERSITY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610010266.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-01-06
Publication Date
2026-04-17

AI Technical Summary

Technical Problem

Existing technologies struggle to distinguish between different types of defects in pharmaceutical quality testing, especially foreign matter defects of the same area but different risk levels. Furthermore, they are sensitive to changes in light intensity and lack the ability to quantify the severity of defects.

Method used

An AI-based approach was used to construct the CIELAB color space and generate dual-channel chromaticity component data. The drug liquid background and suspended matter were located by using the peak center of the color histogram and the fuzzy membership matrix. Combined with the light-transmitting binarized image of aluminum foil and the topology set of the connected components of the packaging, a multidimensional topological severity index and texture entropy value were calculated to achieve comprehensive detection of the drug liquid and packaging.

Benefits of technology

It achieves robust detection of liquid drugs and packaging, can distinguish defects of different risk levels, reduces interference from changes in light, improves the ability to determine complex defects, and enhances the integrity and quantification of the segmentation of tiny foreign objects.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121883976A_ABST
    Figure CN121883976A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of image recognition, in particular to a medicine quality detection method and system based on AI.The method comprises the following steps that a transmitted light image of injection or oral liquid is collected, a CIELAB color space coordinate system is constructed, two-channel chrominance component data is generated, and the two-channel chrominance component data is obtained; and counting the pixel frequency distribution condition of the dual-channel chromaticity component data in a two-dimensional plane, and positioning a chromaticity aggregation point of the liquid medicine background and the suspended matter. According to the method, the area and appearance irregularity of the defect and the complexity of the internal structure are comprehensively quantified by constructing the packaging connected domain topological set and analyzing the topological structure of the defect, so that the defect types with the same area and different risk levels are distinguished; for example, a slender crack with high harmfulness can be distinguished from a circular pinhole with low harmfulness, and finally, the quantitative indexes such as color difference and texture of foreign matters in the liquid medicine are combined for comparison and judgment, so that the capability of judging complex and critical defects is enhanced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of image recognition technology, and in particular to an AI-based method and system for pharmaceutical quality inspection. Background Technology

[0002] Image recognition technology is a technique that uses computer vision and artificial intelligence algorithms to automate the quality inspection of industrial products.

[0003] Existing technologies largely rely on setting fixed thresholds for RGB or grayscale images, or using simple template matching to identify anomalies. For example, slight fluctuations in ambient lighting on a production line or normal differences in color and transparency between product batches can cause pixel values ​​to exceed preset thresholds, leading to false alarms or missed detections. Furthermore, existing technologies often only assess defects at a "present" or "absent" level, lacking the ability to quantify the severity of defects. For example, a 100-pixel circular bubble and a 100-pixel linear glass fragment are vastly different in terms of chemical quality; the latter poses a far greater risk than the former. However, detection logic based solely on area counting would treat them as equivalent, making it difficult to differentiate risk levels. Therefore, improvements are needed. Summary of the Invention

[0004] The purpose of this invention is to address the shortcomings of existing technologies by proposing an AI-based pharmaceutical quality testing method and system.

[0005] To achieve the above objectives, the present invention adopts the following technical solution: an AI-based pharmaceutical quality testing method, comprising the following steps: Acquire transmitted light images of injection solutions or oral solutions, construct a CIELAB color space coordinate system, generate dual-channel chromaticity component data, statistically analyze the pixel frequency distribution of the dual-channel chromaticity component data in a two-dimensional plane, locate the chromaticity aggregation points of the drug solution background and suspended matter, and obtain the peak center of the color histogram. The peak center of the color histogram is called to iteratively generate a pixel fuzzy membership matrix. Based on the pixel fuzzy membership matrix, the pixels are defined by flocculent edges and classified into categories to obtain the drug liquid foreign matter segmentation region. Collect backlight imaging data of aluminum-plastic packaging, separate the light-transmitting pinhole foreground and the opaque aluminum foil background, generate a light-transmitting binarized image of aluminum foil, identify the independent pixel connected sets and the closed void structures inside the connected sets in the light-transmitting binarized image of aluminum foil, count the number of connected components and the number of holes, construct graph theory node relationships, and obtain the topological set of connected domains of packaging. The packaging connected domain topology set is invoked to calculate and generate a multidimensional topology severity index. The drug liquid foreign object segmentation region is invoked to calculate the average color difference vector magnitude and texture entropy value within the region. The multidimensional topology severity index and texture entropy value are compared and classified with the preset pharmaceutical quality qualification threshold to obtain the pharmaceutical product quality inspection conclusion.

[0006] Preferably, the step of obtaining the peak center of the color histogram is as follows: Acquire transmitted light images of injections or oral solutions, analyze the RGB values ​​of all pixels, calculate the Lab coordinates according to a fixed transformation order, delete the L luminance component, and retain the a red-green component and b yellow-blue component to form dual-channel chromaticity component data. Based on the dual-channel chromaticity component data, an equally spaced two-dimensional chromaticity plane grid is established, the pixel frequency of each grid is counted, the coordinates of the frequency peaks are recorded by row and column index, and adjacent peaks within the distance threshold are merged to obtain a set of chromaticity aggregation points. Based on the set of chromaticity aggregation points, mark the background points and suspended matter points of the drug solution, calculate the peak coordinates of each marked point in the color histogram, determine the peak center according to the category and verify that the coverage ratio meets the requirements, and generate the peak center of the color histogram.

[0007] Preferably, the step of obtaining the pixel fuzzy membership matrix is ​​as follows: The color histogram peak center is invoked to read the a red-green component and b yellow-blue component of each pixel in the image. The pixel number is recorded in row and column order. The a red-green component and b yellow-blue component of each pixel are paired and stored, and an index relationship is established with the corresponding color histogram peak center to form a pixel chromaticity value table. Calculate the color difference distance based on the pixel chromaticity value table; Based on the color difference distance, the center corresponding to the minimum color difference distance is taken as the initial pixel classification. The probability normalization and update cycle is performed sequentially according to the classification of each pixel until the change in the classification probability of all pixels is lower than the set threshold, thus generating a pixel fuzzy membership matrix.

[0008] Preferably, the step of obtaining the drug solution foreign matter segmentation region is as follows: Based on the pixel fuzzy membership matrix, the probability of all centers is read pixel by pixel, and the index of the center corresponding to the highest probability is taken as the pixel category label. The pixel category labels of adjacent pixels are compared according to the eight-neighborhood, and the position of category change is marked as the floating object edge candidate. A probability confidence threshold is set to remove the floating object edge candidate with the highest probability below the probability confidence threshold. The eight-neighborhood connectivity label is performed on the pixels marked as floating objects. Connected blocks connected to the floating object edge candidates are merged and isolated connected blocks below the area threshold are deleted to form the drug liquid foreign object segmentation region.

[0009] Preferably, the step of acquiring the light-transmitting binarized image of the aluminum foil is as follows: Collect backlight imaging data of aluminum-plastic packaging, set grayscale threshold rules, mark pixels with grayscale greater than the threshold as light-transmitting pinhole foreground, and mark pixels with grayscale less than or equal to the threshold as opaque aluminum foil background. Delete isolated pixels at the image edges according to the area threshold, retain the pixel row and column indices, and generate a light-transmitting binarized image of aluminum foil.

[0010] Preferably, the step of obtaining the packaged connected component topology set is as follows: Based on the light-transmitting binarized image of the aluminum foil, scan row by row and column by column according to the eight neighborhoods. Write the same connected set number for consecutive foreground pixels. Track pixel by pixel along the outer contour of the connected set. When a closed path is encountered, register it as a closed hole structure. Record the connected set number, the coordinates of the circumscribed rectangle and the area. Record the closed hole structure number, the connected set number to which it belongs and the area. The connected set and hole labeling results are obtained. Based on the connected set and hole labeling results, the number of connected components in the entire graph is counted, the number of holes in each connected component is counted, nodes are established according to the connected components, edges are constructed according to the contact relationship of adjacent pixels, and the area, perimeter and number of holes are written to the nodes to form a topological set of the wrapped connected domain.

[0011] Preferably, the steps for obtaining the multidimensional topology severity index are as follows: The packaged connected component topology set is called, the area, perimeter and number of internal holes of each connected component node are read, the number of each connected component is matched with the corresponding hole number, the geometric morphology parameters and hole parameters of all connected components are recorded, the number of connected components in the whole graph is counted, the number of holes in the whole graph is counted, and a statistical record of the number of connected components and the number of holes is generated. Based on the statistical records of the number of connected components and the number of holes, a multidimensional topology severity index is calculated.

[0012] Preferably, the steps for obtaining the quality inspection conclusion of the pharmaceutical product are as follows: Based on the multidimensional topological severity index, the drug liquid foreign object segmentation region is called, the average color difference vector magnitude of the a red-green component and the b yellow-blue component of all pixels in the region is calculated, the texture entropy value of the pixel distribution is counted, and the multidimensional topological severity index, average color difference vector magnitude and texture entropy value are compared with the pharmaceutical quality qualification threshold, the result labels are classified and output, and a pharmaceutical product quality inspection conclusion is generated.

[0013] The present invention also provides a pharmaceutical quality testing system, comprising: The image acquisition and colorimetric analysis module is used to acquire transmitted light images of injections or oral liquids, construct the CIELAB color space coordinate system, generate dual-channel colorimetric component data, statistically analyze the pixel frequency distribution of the dual-channel colorimetric component data in a two-dimensional plane, locate the colorimetric aggregation points of the drug liquid background and suspended matter, and obtain the peak center of the color histogram. The foreign object detection and segmentation module is used to call the peak center of the color histogram, iteratively generate a pixel fuzzy membership matrix, and perform flocculent edge definition and category classification on the pixels based on the pixel fuzzy membership matrix to obtain the drug liquid foreign object segmentation area. The packaging defect identification module is used to collect backlight imaging data of aluminum-plastic packaging, separate the light-transmitting pinhole foreground from the opaque aluminum foil background, generate a light-transmitting binary image of aluminum foil, identify the independent pixel connected sets and the closed void structures inside the connected sets in the light-transmitting binary image of aluminum foil, count the number of connected components and the number of holes, construct graph theory node relationships, and obtain the topological set of connected domains of packaging. The quality assessment and judgment module is used to call the topology set of the connected components of the packaging, calculate and generate a multidimensional topology severity index, call the foreign matter segmentation region of the liquid medicine, calculate the average color difference vector magnitude and texture entropy value within the region, compare and classify the multidimensional topology severity index and texture entropy value with the preset pharmaceutical quality qualification threshold, and obtain the pharmaceutical product quality inspection conclusion.

[0014] Compared with the prior art, the advantages and positive effects of the present invention are as follows: This invention constructs the CIELAB color space and extracts chromaticity components independent of brightness to analyze drug liquid images, enabling robust expression of color features and reducing interference caused by uneven lighting or differences in liquid translucency during detection. Furthermore, it employs fuzzy membership iteration calculation to define foreign object edges. Compared to traditional hard threshold segmentation, this method can more flexibly handle low-contrast defects with blurred boundaries and irregular shapes, such as flocculent material, improving the integrity of small foreign object segmentation. Simultaneously, for packaging integrity detection, it goes beyond simply identifying light-transmitting points. Instead, it constructs a topological set of connected components within the packaging, analyzes the topological structure of defects, and comprehensively quantifies the area, irregularity of shape, and complexity of internal structure. This allows for the differentiation of defect types with the same area but vastly different risk levels; for example, it can distinguish between highly hazardous slender cracks and less hazardous circular pinholes. Finally, it combines these findings with quantitative indicators such as color difference and texture of foreign objects inside the drug liquid for comparison and judgment, enhancing the ability to identify complex and critical defects. Attached Figure Description

[0015] Figure 1 This is a schematic diagram of the steps of the present invention. Detailed Implementation

[0016] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.

[0017] Please see Figure 1 This invention provides a technical solution, an AI-based pharmaceutical quality testing method, comprising the following steps: Acquire transmitted light images of injections or oral solutions, construct a CIELAB color space coordinate system, generate dual-channel chromaticity component data, statistically analyze the pixel frequency distribution of dual-channel chromaticity component data in a two-dimensional plane, locate the chromaticity aggregation points of the drug solution background and suspended matter, and obtain the peak center of the color histogram. The peak center of the color histogram is called to iteratively generate the pixel fuzzy membership matrix. Based on the pixel fuzzy membership matrix, the pixels are defined by flocculent edge and classified into categories to obtain the drug liquid foreign matter segmentation region. Collect backlight imaging data of aluminum-plastic packaging, separate the light-transmitting pinhole foreground and the opaque aluminum foil background, generate a light-transmitting binarized image of aluminum foil, identify the independent pixel connected sets and the closed void structure inside the connected sets in the light-transmitting binarized image of aluminum foil, count the number of connected components and the number of holes, construct the graph theory node relationship, and obtain the topological set of connected domains of packaging. The system calls the topology set of the connected components in the packaging to calculate and generate a multidimensional topology severity index. It then calls the foreign matter segmentation region of the liquid medicine to calculate the average color difference vector magnitude and texture entropy value within the region. Finally, it compares and classifies the multidimensional topology severity index and texture entropy value with the preset pharmaceutical quality qualification threshold to obtain the pharmaceutical product quality inspection conclusion.

[0018] The steps to obtain the peak center of the color histogram are as follows: Acquire transmitted light images of injections or oral solutions, analyze the RGB values ​​of all pixels, calculate the Lab coordinates according to a fixed transformation order, delete the L luminance component, and retain the a red-green component and b yellow-blue component to form dual-channel chromaticity component data. Based on the dual-channel chromaticity component data, an equally spaced two-dimensional chromaticity plane grid is established, the pixel frequency of each grid is counted, the coordinates of the frequency peaks are recorded by row and column index, and adjacent peaks within the distance threshold are merged to obtain a set of chromaticity aggregation points. Based on the set of chromaticity aggregation points, mark the background points and suspended matter points of the drug solution, calculate the peak coordinates of each marked point in the color histogram, determine the peak center according to the category and verify that the coverage ratio meets the requirements, and generate the peak center of the color histogram.

[0019] Specifically, the transmitted light image of the injection or oral liquid is acquired. A high-intensity LED backlight is turned on and adjusted to a preset brightness value, such as 2000 lumens. The transparent container containing the liquid is placed in front of the industrial camera lens. The camera's exposure time is set to 500 microseconds to reduce motion blur. Raw RGB image data with a resolution of 2048 x 2048 pixels is acquired. The image matrix is ​​scanned line by line, and the grayscale values ​​of the R, G, and B channels of each pixel are extracted. The acquired RGB values ​​are normalized, mapping their range from 0 to 255 to 0 to 1. A standard sRGB to XYZ color space transformation matrix is ​​called, with the parameters set to standard observer parameters. The normalized RGB vector is converted to tristimulus values ​​XYZ through matrix multiplication. The specific transformation formula is as follows: ,in , , This represents the transformed tristimulus value. , , The values ​​represent the normalized red, green, and blue channel values. The constant terms in the matrix are linear transformation coefficients. Subsequently, the L, a, and b components in the CIELAB space are calculated based on the XYZ values, with the white point reference value used in the calculation process. , , It is usually set to the white point value under the D65 standard light source, using a non-linear function. Processing ratio , and The nonlinear function takes the cube root when the variable is greater than 0.008856; otherwise, a linear approximation is used. The specific calculation yields... , as well as ,in For the luminance component, For red-green components, For the yellow and blue components, after converting all pixels in the image, construct a matrix with the same size as the original. Figure 1 A consistent two-dimensional matrix, only the calculated... Component values ​​and Component values ​​are written to the matrix according to pixel position and are actively discarded. The luminance component is used to eliminate the interference of uneven lighting on color determination. Finally, the a and b values ​​of all pixels are combined and stored to form dual-channel chromaticity component data.

[0020] Based on the dual-channel chroma component data, the values ​​of the a and b components are defined to range from -128 to +127. A two-dimensional array is created as a statistical grid, with a grid step size precision of 1.0, i.e., a 256x256 accumulator matrix is ​​established. All cells in this matrix are initialized to zero. The dual-channel data of each pixel in the image is traversed, and its a and b values ​​are read. The a value is incremented by 128 as the row index, and the b value is incremented by 128 as the column index. The corresponding grid cell is found, and its count is incremented by one. After traversal, a frequency matrix describing the color distribution is obtained. This frequency matrix is ​​smoothed by using a 3x3 Gaussian convolution kernel to perform convolution operations on the grid to suppress isolated high-frequency points caused by random noise. The local peak detection window size is set to 5x5. The smoothed frequency matrix is ​​scanned. If the frequency value of the current grid is greater than a set threshold... If the value is the maximum value within the window, it is determined to be a frequency peak. Set to 0.01% of the total number of pixels, for example, set to 400 for a 4-megapixel image, to remove extremely low-frequency noise interference, and record the coordinates of all peaks that meet the conditions. Then, a peak merging operation is performed to calculate the Euclidean distance between any two peaks. The calculation formula is as follows: ,in For the first The peak position and the first The chromaticity distance of each peak and Given the chromaticity coordinates of the two peaks, set a distance threshold. The threshold is 5.0. This threshold is set based on the human eye's resolution limit for drug color and the uniformity characteristics of the CIELAB space. If two peaks are identified as repeated detections of the same chromaticity clustering region, the new coordinates after merging are calculated by weighting the values ​​according to the frequency values. This process is repeated until the distance between all remaining peaks is greater than the distance threshold, thus obtaining the set of chromaticity clustering points.

[0021] Based on the set of chromaticity clusters, the cumulative pixel frequency of each cluster is read, and all clusters are sorted from high to low frequency. According to the physical characteristics of the liquid image, the highest frequency cluster corresponds to a large area of ​​liquid background and is marked as the main background color point. The second highest frequency cluster with a color difference exceeding a certain value from the background point may correspond to reflections from the container wall or bottle bottom. Clusters with lower frequencies but higher than the minimum effective noise are marked as candidate suspended matter points. For each marked category, the original color frequency distribution grid is traced back, and a boundary is defined with the peak as the center and a radius of... The circular area, in which Set to 8.0, covering all non-zero frequency grids within the region, and use the centroid method to calculate a more accurate peak center. The calculation formula is as follows: ,in The corrected center coordinate vector, It is a local neighborhood set centered on the peak position. For the first The pixel frequency of each grid. For the first The chromaticity coordinate vectors of each grid are used to eliminate quantization errors caused by discretization through weighted averaging. After completing the center calculation, the total number of pixels covered by all marked cluster points is counted, and the proportion of these pixels to the total number of pixels in the entire image is calculated. A coverage ratio threshold of 98% is set. If the calculated ratio is lower than this threshold, it indicates that there are uncaptured color modes, and the aforementioned frequency threshold needs to be reduced. Then, a new search is performed. If the ratio meets the requirements, the current classification and center coordinates are confirmed to be valid. The final determined background center coordinates and the center coordinates of each suspended object are encapsulated according to a predetermined data structure to generate the peak center of the color histogram.

[0022] The steps to obtain the pixel blur membership matrix are as follows: Call the peak center of the color histogram, read the a red-green component and b yellow-blue component of each pixel in the image, record the pixel number in row and column order, pair and store the a red-green component and b yellow-blue component of each pixel and establish an index relationship with the corresponding peak center of the color histogram to form a pixel chromaticity value table. The color difference distance is calculated based on the pixel chromaticity value table. The calculation formula is as follows: ; in, For the first From the pixel to the The color difference distance between the peak centers of the color histogram For the first The red and green component values ​​of each pixel. For the first The b-component values ​​of each pixel (yellow and blue components). For the first The coordinates of the red-green components at the peak center of the color histogram. For the first The coordinates of the yellow and blue components at the peak center of the color histogram. This is a texture influence factor used to adjust the effect of neighboring textures on distance. For the first The local chromaticity dispersion of each pixel is calculated as follows: ,in For the first A local neighborhood window centered on a pixel This represents the number of pixels within the neighborhood window. For the neighboring region The red and green component values ​​of each pixel. For the neighboring region The b-color component values ​​of each pixel; Based on the color difference distance, the center corresponding to the minimum color difference distance is taken as the initial pixel classification. The probability normalization and update cycle is performed sequentially according to the classification of each pixel until the change in the classification probability of all pixels is lower than the set threshold, thus generating a pixel fuzzy membership matrix.

[0023] Specifically, the process involves calling the color histogram peak centers, loading the pre-constructed high-resolution image data matrix from memory, and traversing the coordinates of each pixel in the image in row-major order. A two-dimensional structure array, identical in size to the original image (2048 x 2048 pixels), is created. Each cell of this array stores detailed chromaticity information for the corresponding pixel. The a (red-green) component and b (yellow-blue) component values ​​of each pixel in CIELAB color space are read sequentially. Simultaneously, the color histogram peak center list, including the background center and the suspended object center, generated in the previous steps, is read. An index pointer is created for each pixel, pointing to the initial reference center in the peak center list with the closest Euclidean distance. The row and column number of the current pixel in the image matrix is ​​recorded. coordinates and The coordinates are packaged and written into the corresponding cells of a two-dimensional structure array along with the obtained a component value, b component value, and the established center index relationship. The integrity of all recorded data is checked to see if there are any null values ​​or index out-of-bounds errors. If there are abnormal values, they are filled and corrected using the average value of adjacent pixels. After completing the traversal and recording of more than 4 million pixels in the entire image, the memory area is locked to prevent the data from being accidentally overwritten. This structured data set is defined as the basic data source for subsequent parallel computing, forming a pixel chromaticity value table.

[0024] The formula for calculating the chromatic distance incorporates a weighted adjustment of local texture features on the simple chromatic distance. By combining the texture influence factor with the local chromatic dispersion, the chromatic distance is appropriately amplified in the edge region of complex textured foreign objects, thereby improving the sensitivity of edge segmentation. In smooth regions, the chromatic distance mainly depends on the chromatic difference. This design effectively solves the problem of blurred edges of translucent flocculent substances in liquid medicine when using traditional Euclidean distance.

[0025] and The steps for obtaining the parameters are as follows: directly extract the first pixel from the previously generated pixel chromaticity value table. The real-time component data of each pixel is obtained by acquiring it with a high-precision industrial camera under a D65 standard light source and converting it to a color space. The value range is controlled between -128 and +127 according to the CIE standard. For example, when detecting a batch of glucose injection, the value of the [pixel's] component data is obtained by reading the memory address offset. The specific value of each pixel, if the point is located in the background area of ​​the liquid medicine, its The value typically fluctuates between -5 and +5. The value fluctuates between -2 and +8.

[0026] and The parameter acquisition steps are as follows: First, the list of peak centers of the color histogram generated in the previous steps is retrieved. This list is obtained by statistically analyzing the chromaticity frequency distribution across the entire image and performing peak clustering. It represents the main color category centers in the image, such as background, glass reflection, and suspended foreign objects. Each center contains specific a and b coordinate values, which are retrieved using an index. It directly locates the specific structure in memory, reads its stored floating-point center coordinates, which have been corrected using the centroid method and have sub-pixel accuracy, such as the center of the background. It could be 0.5. It could be 2.1, representing the core position of this category in the color space.

[0027] The steps for obtaining the parameters are as follows: select 1000 sample images containing known types of foreign objects (such as hair, fibers, and glass shards), and set... A grid search is performed with a step size of 0.1 from 0.1 to 5.0 to calculate different... The segmentation accuracy at a certain value is the Dice coefficient. Statistical analysis shows that when... When the value is 1.5, the edge segmentation effect for translucent flocculent matter is optimal, neither over-segmenting noise nor missing weak edges. Therefore, this value is set... .

[0028] The steps for obtaining the parameters are as follows: local chromaticity dispersion reflects the pixel-level chromaticity. The degree of color change within the center's neighborhood, its unit is... , The components are consistent, and the calculation formula is as follows: First, define the neighborhood window. For A 3x3 matrix centered at [center], i.e. (excluding the center point itself) Here, all points within the window are included in the calculation. ), traverse every pixel within the window Calculate its relationship with the center pixel The Euclidean color difference is calculated by summing all color difference values ​​and then dividing by the number of pixels. The average dispersion is obtained; this parameter is calculated in real time, for example, on a smooth background. Approaching 0, and at the edge of the foreign object The value is relatively large.

[0029] Calculations based on parameters: Select a pixel with coordinates (100, 100) in the image as the first... Each pixel has a chromaticity value of [number] chromaticity values. , .

[0030] Select the center of the background peak in the color histogram as the first There is a center, and its coordinates are... , .

[0031] Calculate the basic color difference square term: ; ; Basic Sum of Squares ; Calculate local chromaticity dispersion : For example, within a 3x3 neighborhood centered on this pixel, the average color difference between the surrounding 8 pixels and the center pixel is calculated to be 2.0, i.e. .

[0032] Introducing texture influence factor Calculate the dimensionless texture weight term: ; Substitute into the general formula to calculate : ; The results show that, after considering local texture features, the weighted color difference distance from this pixel to the background center is 7.211, compared to the unweighted Euclidean distance ( The distance is significantly increased, which means that in areas of active texture, it is more difficult for pixels to be classified into the current category, which helps to separate edge pixels and thus achieve finer segmentation.

[0033] Based on the color difference distance, the iterative optimization process of the fuzzy C-means clustering algorithm is initiated. First, each pixel is traversed, and its weighted color difference distance to the peak center of each color histogram is compared. Find the center index corresponding to the smallest distance value, mark this index as the initial dominant class of the pixel, and initialize the membership matrix based on the initial classification results. , of which elements Indicates the first The pixel belongs to the first The probability of each class is initially set to 0.8 for the dominant class, and the remaining probabilities of the other classes are evenly distributed among them, with the remaining 0.2. An iterative update loop is then initiated. In each iteration, the probability is adjusted according to the formula... Recalculate the membership degree of each pixel to each center, where the blur index The threshold value is set to 2.0. This value is an empirical value determined through multiple experiments based on the blurring characteristics of the drug liquid image. It is used to control the flexibility of clustering. After calculation, the membership vector of each pixel is normalized to ensure that the sum of the membership degrees of a pixel to all categories is strictly equal to 1.0. Then, the difference of the Frobenius norm of the membership matrix in the two iterations is calculated, and this difference is compared with the preset convergence threshold. The convergence threshold was compared. Set as This value comes from a test of the balance between the convergence speed and accuracy of the algorithm. If the difference is greater than the threshold, the next iteration continues. If the difference is less than or equal to the threshold, or the number of iterations reaches the preset maximum limit, such as 100 times, the algorithm is determined to have converged, the loop stops, the probability distribution data in the final stable state is output, and the pixel blur membership matrix is ​​generated.

[0034] The steps for obtaining the foreign body segmentation region of the drug solution are as follows: Based on the pixel fuzzy membership matrix, the probability of all centers is read pixel by pixel, and the index of the center corresponding to the highest probability is taken as the pixel category label. The pixel category labels of adjacent pixels are compared according to the eight-neighborhood, and the position of category change is marked as the floating object edge candidate. A probability confidence threshold is set to remove the floating object edge candidate with the highest probability below the probability confidence threshold. The eight-neighborhood connectivity label is performed on the pixels marked as floating objects. Connected blocks connected to the floating object edge candidates are merged and isolated connected blocks below the area threshold are deleted to form the drug liquid foreign object segmentation region.

[0035] Specifically, based on the pixel fuzzy membership matrix, the probability values ​​of each pixel's affiliation to each cluster center stored in memory are loaded. Image coordinates are accessed sequentially in row-major order, comparing the probability values ​​of the pixel in all channels such as background, suspended objects, and reflections. The pixel with the highest probability value is selected, and its corresponding category index number is used as the final classification label, thus generating a preliminary classification index map. Subsequently, edge detection is performed on the classification index map. A 3x3 eight-neighbor window is constructed centered on the current pixel, comparing the category labels of the center pixel with its eight neighboring pixels. If there are discrepancies, the center pixel is marked as a candidate point for a suspended object edge. To reduce false edge interference caused by image noise, a probability confidence filtering mechanism is introduced, setting a probability confidence threshold. The threshold is set based on statistical analysis of a large number of known samples. For example, 500 standard sample images containing real foreign objects are selected, and the distribution of the maximum probability value of pixels at manually marked edges is statistically analyzed. The 15th percentile of its cumulative distribution function is taken as the threshold. For example, the calculated threshold is... The algorithm reads the maximum probability value of edge candidate points. If the probability is below 0.65, the classification confidence is considered insufficient, and the point is removed from the candidate list, retaining only edge points with high confidence. Next, a connected component labeling algorithm is performed on all pixels labeled as suspended objects, using a two-pass scanning method. The first pass assigns temporary labels and records equivalence pairs; the second pass parses the equivalence table and merges connected regions. During connectivity analysis, connected components spatially adjacent to the retained high-confidence edge candidate points are forcibly merged to ensure the integrity of the foreign object region. Finally, morphological filtering is performed, setting a minimum area threshold. This threshold is set based on the physical resolution of the imaging system and the minimum visible foreign object size specified in the pharmacopoeia. For example, if the system resolution is 10 micrometers per pixel and the minimum detectable foreign object diameter is 50 micrometers, then the corresponding area is approximately 20 pixels. This threshold is set to account for digitization errors. It iterates through all connected components, counts the number of pixels they contain, and deletes isolated tiny connected components with fewer than 15 pixels as random noise. Finally, it outputs a binarized mask after cleaning and merging to form the drug liquid foreign object segmentation region.

[0036] The steps for obtaining the light-transmitting binarized image of aluminum foil are as follows: Collect backlight imaging data of aluminum-plastic packaging, set grayscale threshold rules, mark pixels with grayscale greater than the threshold as light-transmitting pinhole foreground, and mark pixels with grayscale less than or equal to the threshold as opaque aluminum foil background. Delete isolated pixels at the image edges according to the area threshold, retain the pixel row and column indices, and generate a light-transmitting binarized image of aluminum foil.

[0037] Specifically, the backlight imaging data of the aluminum-plastic packaging is collected, the high-brightness LED backlight is turned on and stabilized to achieve a stable light intensity, and an industrial camera is triggered to take pictures at a preset exposure time, such as 200 microseconds, to obtain the transmission grayscale image of the aluminum-plastic blister. Since the intact aluminum foil completely blocks the light while the pinholes allow light to pass through, a grayscale threshold needs to be set. To separate the foreground from the background, an adaptive statistical method was used to set the threshold. One hundred defect-free aluminum foil images were selected as a benchmark, and the average gray value of the background area was calculated. with standard deviation According to 3 The criteria are set with a safety margin, and the formula is defined as follows: For example, if the measured average gray level of the background is 15 and the standard deviation is 3, then the threshold is calculated as follows: The process iterates through each pixel in the image, reads its grayscale value, and compares it with 33. If the grayscale value is greater than 33, it is determined to be a pinhole foreground where light can pass through and marked as 1; otherwise, it is determined to be an opaque background and marked as 0. This generates a preliminary binarization matrix. Subsequently, interference from image edges is processed. Since the cropping process may cause light to pass through the packaging edges, a width of... is defined. The edge shielding band, for example, is set to 50 pixels, forcing all values ​​within a 50-pixel radius around the image to be zero, further eliminating thermal noise generated by the sensor itself, and setting an isolated pixel area threshold. Based on the sensor parameters, isolated bright spots of 1 to 2 pixels in size are regarded as noise. All foreground connected components are checked. If the area is less than or equal to 2 pixels, it is flipped to become the background. Finally, the processed binary matrix is ​​stored sparsly, and only the row and column numbers of the foreground pixels are retained to reduce the amount of data, thus generating a light-transmitting binary image of aluminum foil.

[0038] The steps to obtain the topology set of the wrapped connected components are as follows: Based on the light-transmitting binarized image of aluminum foil, scan row by row and column by column according to the eight neighborhoods. Write the same connected set number for consecutive foreground pixels. Track pixel by pixel along the outer contour of the connected set. When a closed path is encountered, register it as a closed hole structure. Record the connected set number, the coordinates and area of ​​the circumscribed rectangle, and the closed hole structure number, the connected set number to which it belongs and the area. The connected set and hole annotation results are obtained. Based on the connected sets and hole annotations, the number of connected components in the entire graph is counted, the number of holes in each connected component is counted, nodes are established according to the connected components, edges are constructed according to the contact relationship between adjacent pixels, and the area, perimeter and number of holes are written to the nodes to form a topological set of the wrapped connected domains.

[0039] Specifically, based on the binary image of the aluminum foil, an optimized contour tracing algorithm, such as the Suzuki 85 algorithm, is invoked to perform a full scan of the binary image data. When a non-zero foreground pixel is detected and has not yet been marked, a new connected set is identified, a new unique integer number is assigned, and the outer contour boundary is traced counterclockwise from this pixel, recording the coordinate sequence of all pixels on the boundary. If, during the tracing process, a region with a pixel value of 0 is found inside the connected set and is completely surrounded by foreground pixels, it is identified as a closed void structure, and a unique void number is assigned. A parent-child relationship index is established between this void number and the current connected set number. While tracing, geometric properties are calculated, all pixel coordinates of the connected set are traversed, the minimum and maximum values ​​of the row and column coordinates are found, and the bounding rectangle is constructed. The Box function calculates the width, height, and vertex coordinates of a rectangle. It also calculates the area of ​​the connected set using Green's theorem or by directly counting the total number of pixels. For detected closed holes, it counts the number of background pixels contained within the hole as the hole area. All the calculated connected set numbers, bounding rectangle parameters, entity areas, hole numbers, hierarchical relationships, and hole areas are encapsulated into a structure array to obtain the connected set and hole annotation results.

[0040] Based on the connected sets and hole annotations, the structure array generated in the previous steps is traversed, and the length of the connected set list is accumulated to count the total number of connected components in the entire graph. This value directly reflects the number of suspected defect points on the aluminum foil surface. Then, each connected component object is explored, and its associated hole list is retrieved. The number of closed holes contained within each connected component is counted, which serves as a topological feature to measure the complexity of the defect morphology. Subsequently, a connected domain topology graph of the packaging surface is constructed. A graph node object is created for each independent connected component, and the previously extracted pixel area and the counted number of holes are written into the attribute field of the node. The perimeter attribute is also calculated. By traversing the contour pixel chain code of the connected components, the Euclidean distance between adjacent pixels is accumulated. Horizontal or vertical adjacency is counted as 1, and diagonal adjacency is counted as 1.414 to obtain the precise perimeter. Edge relationships are established while constructing nodes. Although pinhole defects are usually discrete, in order to analyze dense defect clusters, a spatial neighborhood check is performed to determine whether the bounding rectangles of different connected components overlap or whether the distance is within the preset neighborhood radius. Within a range of 3 pixels, if the adjacency condition is met, an undirected edge is created between the two corresponding nodes, indicating that the two defects are in contact or extremely close in space. Finally, all nodes, their geometric topological attributes, and the edge connection relationships between nodes are packaged to form a packaged connected domain topology set.

[0041] The steps to obtain the multidimensional topology severity index are as follows: Call the topology set of the wrapped connected components, read the area, perimeter and number of internal holes of each connected component node, match the number of each connected component with the corresponding hole number, record the geometric parameters and hole parameters of all connected components, count the number of connected components in the whole graph, count the number of holes in the whole graph, and generate a statistical record of the number of connected components and the number of holes. Based on the statistical records of the number of connected components and the number of holes, the multidimensional topology severity index is calculated using the following formula: ; in, As a multidimensional topological severity indicator, The total number of connected components. For the first The pixel area of ​​each connected component For reference, the defect area As a severity index, For the first A set of internal holes in a connected component. For the first The pixel area of ​​each hole The porosity factor. For the first The perimeter of each connected component. The factor affecting shape irregularity is the item. Indicates the first The reciprocal of the circularity of a connected component; the larger the value, the more irregular the shape.

[0042] Specifically, the process involves calling the topology set of the connected components of the packaging, initializing the memory pointer to access the graph structure data stored in the heap area. This data contains the geometric and topological information of all potential defective regions on the surface of the aluminum-plastic packaging. An empty statistics list is created to temporarily store the extracted feature data. A depth-first search strategy is used to traverse each node in the topology set. Each node represents an independent connected component, i.e., a potential aluminum foil tear or pinhole defect. The attribute fields of the current node are accessed to read the pre-calculated and stored pixel area and perimeter values ​​of the connected components. Simultaneously, the list of substructures associated with this node is accessed to obtain the number of closed voids contained within it. To ensure the correspondence of the data... Read the unique identifier ID of the connected component and look up the corresponding hole list in the hash table to verify the correctness of the hole attribution. Pack the parameters such as the area, perimeter, number of holes, and total area of ​​the current connected component into the statistics list. During the traversal, set two global counters: one to accumulate the total number of valid connected components and the other to accumulate the total number of holes inside all connected components. After completing the traversal of all nodes in the graph, verify the statistics list and remove records with zero area or abnormal data. Finally, summarize the organized connected component count, hole count, and detailed geometric parameter set to generate a statistical record of the connected component count and hole count.

[0043] The multidimensional topological severity index calculation formula not only considers the physical size (area) of the defect, but also integrates the internal topological structure (porosity) and edge morphological complexity (circularity). Through the adjustment of the exponential amplification effect and weighting factor, it can produce a highly sensitive response to small but complex malignant defects (such as tear-like pinholes), thereby overcoming the drawback of the single area threshold method that is prone to missing irregular small defects.

[0044] The steps for obtaining the parameters are as follows: the total number of connected components; for example, in a single detection, if three independent light-transmitting regions are identified using a connected component analysis algorithm, then... .

[0045] The steps to obtain the parameters are as follows: The pixel area of ​​the nth connected component is obtained by traversing the statistical list. The area is obtained from each record. It is calculated based on the total number of connected pixels in the binarized image, expressed in square pixels. For example, if the first defect region consists of 200 pixels, then... .

[0046] The parameter acquisition steps are as follows: Using the defect area as the reference denominator for normalization, the denominator is set based on the minimum tolerance limit for pinhole diameter in the pharmaceutical packaging quality inspection standard. First, the resolution of the industrial camera is determined. For example, each pixel represents an actual physical size of 10 micrometers by 10 micrometers, or 100 square micrometers. If the standard specifies a pinhole with a diameter of 0.1 millimeters (100 micrometers) as a critical defect, its area is approximately 7854 square micrometers, which translates to approximately 78.5 pixels. To facilitate calculation and increase safety redundancy, the resolution is set... It is 50 pixels, that is .

[0047] The steps for obtaining the parameters are as follows: The severity index, used to adjust for the non-linear effect of the area ratio on the severity score, is obtained through regression analysis of historical defect data. 1000 defect samples of different areas are collected, and senior quality inspectors score their severity (from 0 to 10 points) to establish the area ratio. With rating Functional relationship Solving by least squares fitting The calculation results show that when When the value is 1.2, the correlation between the model score and the human score is the highest, therefore, we set it to 1.2. .

[0048] and The steps to obtain the parameters are as follows: It is the first The set of all holes within a connected component. It is the first in the set The pixel area of ​​each hole is obtained by querying the parent-child relationships in the topology. For example, if the first connected component contains two small opaque residual points (i.e., holes) with areas of 5 pixels and 8 pixels respectively, then... , .

[0049] The steps for obtaining the parameters are as follows: A void influence factor is used to quantify the impact of the degree of internal fragmentation of defects on quality. This value is set based on light penetration experiments. For defects of the same area, more internal voids mean more fragmented edges and a higher risk of sealing failure. By comparing leakage test data of solid pinholes and mesh pinholes, it was found that the leakage probability of mesh pinholes is about 1.5 times that of solid pinholes. Therefore, an amplification factor is set for the weighting of the void proportion. This is to strengthen the punishment for defects in complex internal structures.

[0050] The steps to obtain the parameters are as follows: The perimeter of each connected component is calculated using a chain code tracing algorithm. The path length is calculated by walking around the edge pixels of the defect; for example, if the edge path length of the first defect is 60 pixels, then... .

[0051] The steps for obtaining the parameters are as follows: The shape irregularity influence factor is used to adjust the contribution of roundness to the index; the ideal circle... The value equals 1, and the more irregular the shape, the larger the value. To screen for tearing cracks (which typically have a very large perimeter-to-area ratio), a set of typical crack defect samples is selected, their average shape factor is calculated, and a setting is made. This makes crack defects The value is 30% higher than that of a circular defect of the same area. Through reverse calculation, it is set... .

[0052] Calculations based on parameters: A connected component has been detected. ), that is, the first defect area.

[0053] The area Pixel.

[0054] It contains two cavities, the sum of which is... Pixel.

[0055] Perimeter of the area Pixel.

[0056] Reference setting parameters: , , , .

[0057] Calculate the first item (area severity): ; Calculate the second term (impact of holes): ; Calculate the third term (shape effect): Pi Take 3.14159.

[0058] ; Shape irregularity item: ; Calculate the overall index : ; The results show that the multidimensional topological severity index of the defect is 7.252, which is much larger than the benchmark value (approximately 4 if only the area ratio is considered). This indicates that the defect not only exceeds the area limit, but also has internal broken voids and irregular edges, which are high-risk tearing damages that require close attention.

[0059] The steps for obtaining the quality inspection conclusions of pharmaceutical products are as follows: Based on the multidimensional topological severity index, the drug liquid foreign object segmentation region is called, the average color difference vector magnitude of the a red-green component and the b yellow-blue component of all pixels in the region is calculated, the texture entropy value of the pixel distribution is statistically analyzed, and the multidimensional topological severity index, average color difference vector magnitude and texture entropy value are compared with the pharmaceutical quality qualification threshold, the result labels are classified and output, and the pharmaceutical product quality inspection conclusion is generated.

[0060] Specifically, based on the multidimensional topological severity index, the final comprehensive quality assessment stage begins. First, the data of the drug solution foreign object segmentation region stored in memory is loaded. Each pixel within this region is traversed, and its a and b components in the CIELAB color space are read. Simultaneously, the average chromaticity value of the background region is read as a reference vector. The magnitude of the color difference vector of each pixel relative to the background reference is calculated. The magnitudes of all pixels within the region are summed and divided by the total number of pixels to obtain the average color difference vector magnitude. This index reflects the salience of the foreign object's color. Next, the texture entropy value is calculated, and a gray-level co-occurrence matrix of the foreign object region is constructed. Based on this matrix, the entropy value is calculated, reflecting the texture complexity of the foreign object's surface. Finally, a preset set of pharmaceutical quality qualification thresholds is retrieved. This set contains three independent threshold standards: severity index threshold... Set to 5.0, color difference threshold Set to 10.0, texture entropy threshold The threshold is set at 2.5. These thresholds are determined based on national pharmacopoeia standards and the company's internal yield control requirements, through the statistical distribution characteristics of 100,000 historical samples. A grading judgment logic is then executed, first comparing... Indicators, if If the calculation result is 7.252 (as in the previous example), the packaging is directly deemed unqualified and marked as "damaged packaging". If the packaging is qualified, the drug liquid indicators are further compared. If the average color difference vector magnitude is greater than 10.0 or the texture entropy value is greater than 2.5, the drug liquid is deemed unqualified and marked as "visible foreign matter". If all three are below their respective thresholds, the product is deemed qualified. Finally, the corresponding classification result label is output, and the pharmaceutical product quality inspection conclusion is generated.

[0061] The above are merely preferred embodiments of the present invention and are not intended to limit the present invention in any other way. Any person skilled in the art may make changes or modifications to the above-disclosed technical content to create equivalent embodiments that can be applied to other fields. However, any simple modifications, equivalent changes, and modifications made to the above embodiments based on the technical essence of the present invention without departing from the scope of the present invention shall still fall within the protection scope of the present invention.

Claims

1. An AI-based pharmaceutical quality testing method, characterized in that, Includes the following steps: Acquire transmitted light images of injection solutions or oral solutions, construct a CIELAB color space coordinate system, generate dual-channel chromaticity component data, statistically analyze the pixel frequency distribution of the dual-channel chromaticity component data in a two-dimensional plane, locate the chromaticity aggregation points of the drug solution background and suspended matter, and obtain the peak center of the color histogram. The peak center of the color histogram is called to iteratively generate a pixel fuzzy membership matrix. Based on the pixel fuzzy membership matrix, the pixels are defined by flocculent edges and classified into categories to obtain the drug liquid foreign matter segmentation region. Collect backlight imaging data of aluminum-plastic packaging, separate the light-transmitting pinhole foreground and the opaque aluminum foil background, generate a light-transmitting binarized image of aluminum foil, identify the independent pixel connected sets and the closed void structures inside the connected sets in the light-transmitting binarized image of aluminum foil, count the number of connected components and the number of holes, construct graph theory node relationships, and obtain the topological set of connected domains of packaging. The packaging connected domain topology set is invoked to calculate and generate a multidimensional topology severity index. The drug liquid foreign object segmentation region is invoked to calculate the average color difference vector magnitude and texture entropy value within the region. The multidimensional topology severity index and texture entropy value are compared and classified with the preset pharmaceutical quality qualification threshold to obtain the pharmaceutical product quality inspection conclusion.

2. The AI-based pharmaceutical quality testing method according to claim 1, characterized in that, The steps for obtaining the peak center of the color histogram are as follows: Acquire transmitted light images of injections or oral solutions, analyze the RGB values ​​of all pixels, calculate the Lab coordinates according to a fixed transformation order, delete the L luminance component, and retain the a red-green component and b yellow-blue component to form dual-channel chromaticity component data. Based on the dual-channel chromaticity component data, an equally spaced two-dimensional chromaticity plane grid is established, the pixel frequency of each grid is counted, the coordinates of the frequency peaks are recorded by row and column index, and adjacent peaks within the distance threshold are merged to obtain a set of chromaticity aggregation points. Based on the set of chromaticity aggregation points, mark the background points and suspended matter points of the drug solution, calculate the peak coordinates of each marked point in the color histogram, determine the peak center according to the category and verify that the coverage ratio meets the requirements, and generate the peak center of the color histogram.

3. The AI-based pharmaceutical quality testing method according to claim 1, characterized in that, The steps for obtaining the pixel fuzzy membership matrix are as follows: The color histogram peak center is invoked to read the a red-green component and b yellow-blue component of each pixel in the image. The pixel number is recorded in row and column order. The a red-green component and b yellow-blue component of each pixel are paired and stored, and an index relationship is established with the corresponding color histogram peak center to form a pixel chromaticity value table. Calculate the color difference distance based on the pixel chromaticity value table; Based on the color difference distance, the center corresponding to the minimum color difference distance is taken as the initial pixel classification. The probability normalization and update cycle is performed sequentially according to the classification of each pixel until the change in the classification probability of all pixels is lower than the set threshold, thus generating a pixel fuzzy membership matrix.

4. The AI-based pharmaceutical quality testing method according to claim 1, characterized in that, The steps for obtaining the foreign matter segmentation region of the drug solution are as follows: Based on the pixel fuzzy membership matrix, the probability of all centers is read pixel by pixel, and the index of the center corresponding to the highest probability is taken as the pixel category label. The pixel category labels of adjacent pixels are compared according to the eight-neighborhood, and the position of category change is marked as the floating object edge candidate. A probability confidence threshold is set to remove the floating object edge candidate with the highest probability below the probability confidence threshold. The eight-neighborhood connectivity label is performed on the pixels marked as floating objects. Connected blocks connected to the floating object edge candidates are merged and isolated connected blocks below the area threshold are deleted to form the drug liquid foreign object segmentation region.

5. The AI-based pharmaceutical quality testing method according to claim 1, characterized in that, The steps for obtaining the light-transmitting binarized image of the aluminum foil are as follows: Collect backlight imaging data of aluminum-plastic packaging, set grayscale threshold rules, mark pixels with grayscale greater than the threshold as light-transmitting pinhole foreground, and mark pixels with grayscale less than or equal to the threshold as opaque aluminum foil background. Delete isolated pixels at the image edges according to the area threshold, retain the pixel row and column indices, and generate a light-transmitting binarized image of aluminum foil.

6. The AI-based pharmaceutical quality testing method according to claim 1, characterized in that, The steps for obtaining the packaged connected component topology set are as follows: Based on the light-transmitting binarized image of the aluminum foil, scan row by row and column by column according to the eight neighborhoods. Write the continuous foreground pixels into the same connected set number. Track pixel by pixel along the outer contour of the connected set. When a closed path is encountered, register it as a closed hole structure. Record the connected set number, the coordinates of the circumscribed rectangle and the area. Record the closed hole structure number, the connected set number to which it belongs and the area. The connected set and hole labeling results are obtained. Based on the connected set and hole labeling results, the number of connected components in the entire graph is counted, the number of holes in each connected component is counted, nodes are established according to the connected components, edges are constructed according to the contact relationship of adjacent pixels, and the area, perimeter and number of holes are written to the nodes to form a topological set of the wrapped connected domain.

7. The AI-based pharmaceutical quality testing method according to claim 1, characterized in that, The steps for obtaining the multidimensional topology severity index are as follows: Call the packaged connected component topology set, read the area, perimeter and number of internal holes of each connected component node, match the number of each connected component with the corresponding hole number, record the geometric morphology parameters and hole parameters of all connected components, count the number of connected components in the whole graph, count the number of holes in the whole graph, and generate a statistical record of the number of connected components and the number of holes. Based on the statistical records of the number of connected components and the number of holes, a multidimensional topology severity index is calculated.

8. The AI-based pharmaceutical quality testing method according to claim 1, characterized in that, The steps for obtaining the quality inspection conclusions of the pharmaceutical products are as follows: Based on the multidimensional topological severity index, the drug liquid foreign object segmentation region is called, the average color difference vector magnitude of the a red-green component and the b yellow-blue component of all pixels in the region is calculated, the texture entropy value of the pixel distribution is counted, and the multidimensional topological severity index, average color difference vector magnitude and texture entropy value are compared with the pharmaceutical quality qualification threshold, the result labels are classified and output, and a pharmaceutical product quality inspection conclusion is generated.

9. The pharmaceutical quality testing system based on the AI-based pharmaceutical quality testing method according to any one of claims 1-8, characterized in that, include: The image acquisition and colorimetric analysis module is used to acquire transmitted light images of injections or oral liquids, construct the CIELAB color space coordinate system, generate dual-channel colorimetric component data, statistically analyze the pixel frequency distribution of the dual-channel colorimetric component data in a two-dimensional plane, locate the colorimetric aggregation points of the drug liquid background and suspended matter, and obtain the peak center of the color histogram. The foreign object detection and segmentation module is used to call the peak center of the color histogram, iteratively generate a pixel fuzzy membership matrix, and perform flocculent edge definition and category classification on the pixels based on the pixel fuzzy membership matrix to obtain the drug liquid foreign object segmentation area. The packaging defect identification module is used to collect backlight imaging data of aluminum-plastic packaging, separate the light-transmitting pinhole foreground from the opaque aluminum foil background, generate a light-transmitting binary image of aluminum foil, identify the independent pixel connected sets and the closed void structures inside the connected sets in the light-transmitting binary image of aluminum foil, count the number of connected components and the number of holes, construct graph theory node relationships, and obtain the topological set of the connected domain of the packaging. The quality assessment and judgment module is used to call the topology set of the connected components of the packaging, calculate and generate a multidimensional topology severity index, call the foreign matter segmentation region of the liquid medicine, calculate the average color difference vector magnitude and texture entropy value within the region, and compare and classify the multidimensional topology severity index and texture entropy value with the preset pharmaceutical quality qualification threshold to obtain the pharmaceutical product quality inspection conclusion.